Friday, September 11, 2020

Core concept of Containers and Docker - installation & some basic commands

 Docker

In this post we will discuss about Docker and its features.

lets get started,

server: its a physical machine (OS) and that is gong to be manage the application deployed and that application can be serverd.

virtual machine: is also a box on top of it there are several physical machines will run , each VM responsible for the one of the application should be serverd.

container: is also a dedicated platform , where we are going to run the application to be serverd.

actual use case prospective there is no difference among 3 models.so our target is to run the application either top of Server, or top of VM or top of Container.

if you think about structure, cost and the functionalities, there are huge differences of 3 models.

lets understand the concepts and how container is going to provision in linux boxes.

firstly we have to understand cgroups ,  it is the utility which is available in OS, which will helps to assigned CPU and Memory to the each process.

this utility was there in OS from long time, but in containerization environment we are using widely for assigning CPU & Memory to the specific container. 

now lets understand about Namespaces, there are so many organs or components, those are physical components and  logical components, in order to function our OS, logical components will help and those available in  linux box.

PID : which will manage the process those are running on OS

MNT: which will manage file system structure of OS

NET: which will manage networks on the OS(in/out communications)

IPC: which will manage memory sharing on the OS

UTS: which will manage identification information on OS.

from kernel 2.6 they defined all 5 components are as Namespaces, each component as its own Namespaces, like PID Namespaces, MNT Namespaces ...

also from 2.6 they have introduced cloning the namespaces , we can create number of  clone namespaces on the linux box( with 5 primary namespaces) and join those.

now lets understand about Images. it is a binary that includes all of the requirements for running the application.

when ever we are creating the container, our created platform can be created through Namespaces, and resource allocation done through cgroup. on top of platform we need applications right that is basically through Images.

so collaboration of Namespace, Cgroups and the Images is knows as Containers. 

Technically each container considered as a process in OS prospective.

each containers has its dedicated network, dedicated storage and dedicated process space.

containers are isolated piece of linux box. it may be 1 or more we can create. there is no relation between one container to another containers.

as a difficult task to OS to collaboration of 3 (Namespace, cgroups and Images),so in order to makes easiest provisioning and we use something tool called as Docker.

Docker is container technology which is launched in 2013 as an Open source 

Docker is a kind of software which is helps to create container/run the container/delete the container on the linux boxes.

Docker alone will won't provision the container, Docker will use OS functionalities  to create the container.

we can containerize any type of application by using Docker. it won't do any orchestration stuff.

in order to do our application to containerized we have to collect the information of our application then create the image based on docker file and from that we can as container and that will use in any platforms.

We will learn how to install Docker and usage of some basic docker commands.

Docker installation steps on centos:

Login to any of the Cloud platforms and login as root and execute the below commands one by one in centos 7.

  • yum update

  • yum install -y yum-utils device-mapper-persistent-data lvm2

  • yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

  • yum search --show-duplicates docker-ce
  • yum install docker-ce-19.03.0-3.el7.x86_64

  • systemctl start docker

  • systemctl enable docker  

To check the docker version : docker -v  ( for shorter output)










To check the docker version : docker version  ( for full output)

















I'm installing Ubuntu container in the box. with Ubuntu image.

docker run -itd --name container1 ubuntu is the command with detached mode.








To verify Namespaces and the Cgroups associated to the created Docker container

before creating the Ubuntu container : see the Namespaces List as below

lsns command to list the namespaces on the box.







before creating the Ubuntu container : see the cgroups List as below


systemd-cgls  is command to list the cgroups on the box.












Some default cgroups can be shown in the above screen, there is no specific Cgroups for the container image which we have created.

After creating the Ubuntu container: see the namespaces List as below

Yellow coloured highlighted namespaces are created.








After creating the Ubuntu container : see the cgroups List as below

systemd-cgls  is command to list the cgroups on the box.










let us see the creating of the other container with same Ubuntu image to verify the Namespace and the cgroups. it will give us a clear picture that each container is isolated on the linux box with Namespaces, cgroups and images

creating container2 :






for container2 we have got same set of namespaces & cgroups with different PID. 











Basic Commands:

docker ps   --> list of the containers

docker run -itd --name Container-Name image:tag   --> to run the container with detached mode

docker run -it --name Container-Name image:tag  --> o run the container with atached mode

docker ps -a   --> for list of the stopped containers

docker login  --> for login to docker hub account

docker logout --> for logout from docker hub account

ps -eaf | grep docker  | wc -l


Image Commands:

  build       Build an image from a Dockerfile

  history     Show the history of an image

            ex:  docker history sravanakumar28 /myrepos:sampleapp

  import      Import the contents from a tarball to create a filesystem image

  inspect     Display detailed information on one or more images

            ex: docker inspect sravanakumar28 /myrepos:sampleapp

  load        Load an image from a tar archive or STDIN

            ex: docker load -i /opt/img.tar

  ls          List images

            ex: docker images ls

  prune       Remove unused images

            ex: docker image  prune -a

  pull        Pull an image or a repository from a registry

            ex: docker pull centos:7

  push        Push an image or a repository to a registry

            ex:  docker push centos:7

  rm          Remove one or more images

  save        Save one or more images to a tar archive (streamed to STDOUT by                       default)

            ex: docker save tomcat:latest /opt/img.tar

  tag         Create a tag TARGET_IMAGE:TAG that refers to SOURCE_IMAGE:TAG

            ex: docker tag tomcat:latest sravanakumar28:sample

Containers Commands:

docker exec -it <containerID>  /bin/bash

docker pause <containerID>

docker status

docker status <container ID>

docker stop <containerID>

docker start  <containerID>

docker restart <containerID>

docker rm -f <containerID/containerName>  -- > to delete the container when it is in running state.


No comments:

Post a Comment