Thursday, 16 April 2020

ALL ABOUT DOCKER CONTAINER

– Introduction

  • The container is like a virtual machine in which we can deploy any type of applications, software’s and libraries. It’s a light weight virtual machine which uses OS in the form of image, which is having less in size compare to traditional VMware and oracle virtual box OS images. Container word has been taken from shipping containers. It has everything to run an application.
  • Logically dividing big machine into multiple virtual machines so that each virtual machine acts as new server and we can deploy any kind of applications in it. For this first we install any virtualization software on top of base OS. This virtualization software will divide base machine resources in to logical components. In a simple terms, logically dividing one machine into multiple machines we call virtualization.

– Container Tools

  1. Docker
  2. Kubernetes
  3. AWS ECS/EKS
  4. Azure Container Service
  5. Docker Enterprise
  6. RedHat openShift
  7. Docker Swarm
  8. Google Container Engine (GKE)
  9. Pivotal Cloud Foundry
  10. Mesosphere

– Docker

  • Docker is a tool by using which, we create containers in less time. Docker uses light weight OS in the form of docker images that we will get from docker hub. Docker is open source now. It became so popular because of its unique virtualization concept called “Containerization” which is not there in other tools. We can use docker in both windows and Linux machines.

– Docker image

  • Docker image is light weight OS provided by docker company. We can get any type of docker image form docker hub. We use these docker images to create docker containers. This docker images may contain only OS or OS + other soft wares as well. Each software in docker image, will be stored in the form of layer. Advantage of using docker images is, we can replicate the same environment any no of times.

– Docker image creation

  1. We can take any type of docker image directly from docker hub being provided by docker company and docker community.
  2. We can create our own docker images form our own docker containers. I.e. first we create container form base docker image taken form docker hub and then by going inside container, we install all required soft wares and then create docker image from our own docker container.
  3. We can create docker image form docker file. It is the most preferred way of creating docker images.

– Docker file

  • It is a just normal text file with instructions in it to build docker image. It is the automated way of creating docker images. Once you build docker image, automatically docker file will be created. In this file, we mention required OS image and all required soft wares in the form of instructions. Once we build docker file, back end, docker container will be created and then docker image will be crated from that container and that container will be destroyed automatically.
  • Layered file system/Union file system, Inside docker container, wheat ever we do, that forms as a new layer. For instance, creating files, directories, installing packages etc. This is what we call as layered file system. Each layer takes less space. We can create docker image form this container. In that docker image also we get all these layers and forms unity. That’s why we also call Union File System. If we create container out of docker image, you can able to see all those files, directories and packages. This is what replication of same environment.

– Benefits of Docker

  1. Containerization (OS level virtualization) (No need guest OS)
  2. No pre-allocation of RAM
  3. Can replicate same environment
  4. Less cost & weight (MB’s in size) & Fast to fire up
  5. Can run on physical/virtual/cloud & re-use (same image) in less time

– Docker components

  1. Docker image: – Contains OS (very small) (almost negligible) + soft wares
  2. Docker Container: – Container like a machine which is created from Docker image.
  3. Docker file: – Describes steps to create a docker image.
  4. Docker hub/registry: – Stores all docker images publicly.
  5. Docker daemon: – Docker service runs at back end Above five components we call as Docker components

– Docker workflow

  • First we create Docker file by mentioning instructions to build docker image. Form this Docker image, we are going to create Docker container. This Docker image we can push to docker hub as well. This image can be pulled by others to create docker containers. We can create docker images from docker containers. Like this we can create Docker images form either docker file or docker containers. We can create docker containers from docker images. This is the work flow of docker.
  • Docker Volume :  Volume is a directory inside your container  First declare directory as a volume and then share volume  Even if we stop container, still we can access volume  Volume will be created in one container  You can share one volume across any no of containers  Volume will not be included when you update an image  Map volumes in two ways  Share host – container  Share container – container

– Docker Mapping

  • Suppose if you want to make any container as web server by installing web package in it, you need to provide containers IP address to public in order to access website which is running inside docker container. But Docker containers don’t have an IP address. So, to address this issue, we have a concept called Docker port mapping.
  • We map host port with container port and customers use public IP of host machine. Then their request will be routed from host port to container’s port and will be loaded web page which is running inside docker container. This is how we can access website which is running inside container through port mapping.

– Registry server in Docker

  • Registry server is our own docker hub created to store private docker images instead of storing in public Docker hub.
  • Registry server is one of the docker containers. We create this Registry server from “registry” image, especially provided by docker to create private docker hub.
  • We can store any no of private docker images in this Registry server. We can give access to others, so that, they also can store their docker images whomever you provide access. Whenever we want, we can pull these images and can create containers out of these images.

– Docker commands

  1. Docker ps (to see list of running containers)
  2. Docker ps -a (to see list of all containers)
  3. Docker images (to see list of all images)
  4. Docker run (to create docker container)
  5. Docker attach (to go inside container)
  6. Docker stop (to stop container)
  7. Docker start (to start container)
  8. Docker commit (to create image out of docker file)
  9. Docker rm (to delete container)
  10. Docker rmi (to delete image)

– Thank You

1 comment: