Docker Container | Learn Docker Basics in 30 Mins
Are you looking for docker tutorials.? If your answer is yes, Then good to follow this step by step guide and the below video to learn Docker container basics in 30 minutes. So This article will give you the quick introduction and the installation process of Docker and it’s usage on the enterprise level. Please check the Youtube Video to get more hands-on experience and let’s start with what is Docker first?
What is Docker?
Docker is an open platform for developers and system engineers to build, ship, and run distributed applications, whether on Bare Metal Systems (Physical), VMs, or the Cloud. Docker is not a Linux container technology like Xen/KVM etc.
Docker provides an additional layer of abstraction and automation of operating system l virtualization on Windows and Linux.
Advantages of using Docker
Portability – In Docker system, an application and its prereq’s/dependencies can be bundled into a single container/image, which will be independent of host kernel, can be easily ported to the different system.
Quick Application Deployment – As application and its dependencies can be bundled into single images, it makes easy to quickly deploy the apps.
Sharing – You can share your Docker image with others using remote repositories.
Lightweight – Docker images have very small, they need very low compute capacity and storage,
Easy Maintenance – Maintenance is very quick and easy.
Cost Saving – Open source Technology and don’t need heavy compute.
- Discuss Dockers Terminologies Quickly.
- Docker Container and Virtual Machine Comparison.
- Install Docker Software.
- Discuss Docker Network.
- Downloading a Docker Container.
- Create your Custom Container and Manage the Tags/Repos.
- Discuss Basic Docker Operations – States/Logs/Resources etc.
Docker Containers vs. Virtual Machines
- Docker container can be created/destroyed very quickly as compare to the virtual machines.
- Docker containers are light weight is compared to the virtual machines. Being lightweight more containers can run at the same time on a host.
- Docker container make use of resources very efficiently. In the case of virtual machines capacity is need to be reserved (compute + storage ), whereas this is not needed is a case of Docker containers.
- Virtual Machines can be migrated across servers when they are running, but Docker needs to stop before migration as there is no hypervisor layer.
Source: *Images are taken from Docker Documentations
- Images – Images are templates for the docker containers.
- Containers – Created from Docker images and run the actual application.
- Docker Daemon – The background service running on the host that manages the building, running the containers.
RHEL or CentOS 7 64 Bit / Kernel 3.10.x kernel is the minimum required and docker is part extra packages. so before trying to install docker, make sure you have already installed epel repository on the server. If it is not installed, please follow the below steps to installing the EPEL repository on linux.
Install EPEL repository
# yum install -y epel-release
Install docker Software
# yum install -y docker
Enable and Start Docker service
# systemctl enable docker
# systemctl start docker
Check the Docker Version
# docker version
Check Detailed Docker Information
# docker info
Search Docker Images on the Internet
# docker search centos
Download Docker Image
# docker pull centos:centos7
To display the list of locally available images, type:
# docker images
To test your new image, type
# docker run centos:centos7 /bin/ping opera.com -c 5
List Docker Containers
# docker ps -a
Checking Docker Networking
# docker network ls
# docker network inspect [network Name]
Also, learn more about Custom Networking for Docker Container : Click here
Check Resource Consumption by Running Container#
# docker stats
Setting Resource limits for a docker container
# docker run -it -c 256 -m 300M centos:centos7 /bin/bash
Stop/Start/Restart operations for docker container
# docker start [container ID] ## to start a docker container
# docker stop [container ID] ## to stop a docker container
# docker restart [container ID] ## to restart a docker container
Committing the Docker Container Updates (This command turns your container to an image)
# docker commit [container ID]
Adding a Repository/Tag value to a image
# docker tag [image ID] <repo : tags >
Removing / Deleting a container
# docker rm [container ID]
Checking the docker container Logs
# docker logs [container_id ]
Lets create our container and host a demo website quickly using Python SimpleHTTPServer module which will listen on port 8080.
# mkdir -p /var/www/html
# echo “This is my Yogesh’s Test Docker Website” > /var/www/html/demowebpage.txt
# docker run -d -p 8080:8080 –name=”python_web” -v /usr/sbin:/usr/sbin -v /usr/bin:/usr/bin
-v /usr/lib64:/usr/lib64 -w /var/www/html -v /var/www/html:/var/www/html centos:centos7
/bin/python -m SimpleHTTPServer 8080
-d, –detach Run container in background and print container ID
-p, –publish value Publish a container’s port(s) to the host (default )
-v, –volume value Bind mount a volume (default )
-w, —workdir string Working directory inside the container
Check the Network Ports Allocation
# netstat -tupln | grep 8080
Lets test the Website
# curl localhost:8080/demowebpage.txt
Conclusion: I hope this guide will help you to understand the basics of Docker Container and its usage. Check out the video: click here