Docker : The beginning
Background and Pain Points:
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 .
Now this can happen due to infrastructure misconfiguration, missing dependencies , library etc.
Earlier there was no way to package all the dependencies , libraries , configuration along with the code and deploy it to all the environments.
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
A Virtual Machine is a digital copy of a physical machine.
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.
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
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.
We don’t need to create different environments.
Difference between a Virtual Machine and a Container
Virtual Machine :
Virtual machine used to virtualize a physical machine(Infrastructure) so hardware can be used efficiently and manages the resources of the physical machine.
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.
Each VM’s has a guest operating system and application running on it with all the dependencies , libraries and configurations.
Containers :
Containers are software code package containing an application’s code, its libraries, and other dependencies that make up the application running environment.
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.
Docker engine help us to run multiple container instances with application code packaged in.
Containers can be run on any machine regardless of host operating system or environment configuration.
Docker Workflow
We have a docker file having set of instruction having OS details to be used for image , some tasks to build the image etc.
When the docker file is build to create a docker image having the source code , dependencies, binaries which can be shipped to different environments.
This image will be pushed to Docker registry(Hub). This is like a version control system for docker images since these are the binaries.
Now these images can be pulled to different environments using docker pull command.
Now we run the Docker run command . The binary file will then be converted to the running instance(Container)
Docker Architecture
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.
When docker push command is ran , the docker daemon is called and the docker image is push to the registry.
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.
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:
Subscribe to my newsletter
Read articles from Vijay Patil directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by