Docker : The beginning

Background and Pain Points:

  1. In traditional way of building the code and deploying , a developer used to deploy the code after building it in dev environment and if it works there the same code is deployed to test environment and if code works there as well , it is promoted to Production Now Code fails in Prod environment .

  2. Now this can happen due to infrastructure misconfiguration, missing dependencies , library etc.

  3. Earlier there was no way to package all the dependencies , libraries , configuration along with the code and deploy it to all the environments.

  4. Then came into picture containers

To summarize, there can be issues where different environment can have different versions of operating system. All the environments needs to be maintained and upgraded with same version at all times. There can be issues where different environment can have different versions of operating system.

What are Containers?

A container is a isolated environment that packages up code and all its dependencies, libraries , configurations so the application can runs quickly and reliably for all compute environment

Rise of Virtual Machines

  1. A Virtual Machine is a digital copy of a physical machine.

  2. These were developed to efficiently use the growing processing power and capacity of physical hardware. Many a times only one application was used on one physical machine causing inefficient use of physical hardware.

  3. By use of virtual machines , multiple operating system and environments can be created on physical machine having same configuration as the physical machine

Rise of Containers

  1. Using containers we can package our code , dependencies and libraries and run application across different environment since the packaged code can run on all types of physical or virtual machine.

  2. We don’t need to create different environments.

Difference between a Virtual Machine and a Container

Virtual Machine :

  1. Virtual machine used to virtualize a physical machine(Infrastructure) so hardware can be used efficiently and manages the resources of the physical machine.

  2. Virtual machines are managed by hypervisor which reside on top of host operating system. Hypervisor is a Software layer that allows multiple VMs to run on a single physical machine and helps communication between Host OS and Guest OS.

  3. Each VM’s has a guest operating system and application running on it with all the dependencies , libraries and configurations.

Containers :

  1. Containers are software code package containing an application’s code, its libraries, and other dependencies that make up the application running environment.

  2. Containers virtualize a operating system. Containers are operated by container engine or container runtime. Docker engine act an intermediary agent between the containers and the operating system for managing system resource.

  3. Docker engine help us to run multiple container instances with application code packaged in.

  4. Containers can be run on any machine regardless of host operating system or environment configuration.

Docker Workflow

  1. We have a docker file having set of instruction having OS details to be used for image , some tasks to build the image etc.

  2. When the docker file is build to create a docker image having the source code , dependencies, binaries which can be shipped to different environments.

  3. This image will be pushed to Docker registry(Hub). This is like a version control system for docker images since these are the binaries.

  4. Now these images can be pulled to different environments using docker pull command.

  5. Now we run the Docker run command . The binary file will then be converted to the running instance(Container)

Docker Architecture

  1. When we run on docker build command on a Docker File in docker client. Docker Daemon is called and it will build the image and store on your local machine where docker is running.

  2. When docker push command is ran , the docker daemon is called and the docker image is push to the registry.

  3. Now if we need to deploy image to environment .A docker client running on the environment, when docker run command is ran, docker daemon is called. This will pull the image from registry to the environment.

  4. When docker run command is ran, it is issued to docker daemon , docker daemon then instruct docker run time to spin up the container.

Resources and articles used:

  1. What are virtual machines and containers? by AWS