The Rise of Containerization and Docker

khalis murfid
Inside PPL B7
Published in
5 min readApr 27, 2020
Photo by Rahul Chakraborty on Unsplash

What is Docker and why do we need it?

Imagine you have written code in Python using some library. You now want to share the code with your friend. The code works fine in your machine but gives an error on their computer.

You figure out the issue is with a different version of the library you used.

What if you could package your code along with all dependent libraries and ship it to your friend.

This is where Docker comes to your rescue!

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.

I don’t know about you but the first time I hear about docker, I also think about VM or Virtual Machine. To understand docker, I think it's important to know about a virtual machine.

What is a VM (Virtual Machine)?

A VM is a virtual server that emulates a hardware server. A virtual machine relies on the system’s physical hardware to emulate the exact same environment in which you install your applications. Depending on your use case, you can use a system virtual machine (that runs an entire OS as a process, allowing you to substitute a real machine for a virtual machine), or process virtual machines that let you execute computer applications alone in the virtual environment.

Earlier, we used to create virtual machines, and each VM had an OS which took a lot of space and made it heavy. I personally used VM for my school project and it’s kinda laggy.

Then What’s the Difference?

When compared to Virtual machines, the Docker platform moves up the abstraction of resources from the hardware level to the Operating System level. This allows for the realization of the various benefits of Containers e.g. application portability, infrastructure separation, and self-contained microservices.

In other words, while Virtual Machines abstract the entire hardware server, Containers abstract the Operating System kernel. This is a whole different approach to virtualization and results in a much faster and more lightweight instances.

Source

Docker runs multiple containers; containers are isolated environments that package application and dependent libraries. Containers are the unit for developing, testing, and deploying applications. Containers are light-weight compared to VM’s.

Docker images don’t have the extra load of a hypervisor like VM’s. VM’s use heavy disk space usually in GB, whereas Containers are light-weight often in MB. Containers run directly within the OS kernel. Each VM has an OS inside them, and each VM can have a different OS on the same hardware infrastructure

More Containers can be run on the same hardware compared to a VM as they are Containers light-weight and use the same OS kernel.

Docker Orchestration

After we understand what is docker and what’s the thing that differentiates a docker and a VM, we need to know how docker orchestration works. Docker orchestration or container orchestration is all about managing the lifecycles of containers, especially in large, dynamic environments. Software teams use container orchestration to control and automate many tasks.

Docker orchestration automates the deployment, management, scaling, and networking of containers. It can be used in any environment where you use containers. It can help you to deploy the same application across different environments without needing to change it. Those are the tasks that can be a pain to manage it manually. It can help to automate:

  • Provisioning and deployment of containers
  • Redundancy and availability of containers
  • Scaling up or removing containers to spread application load evenly across host infrastructure
  • Movement of containers from one host to another if there is a shortage of resources in a host, or if a host dies
  • Allocation of resources between containers
  • External exposure of services running in a container with the outside world
  • Load balancing of service discovery between containers
  • Health monitoring of containers and hosts
  • Configuration of an application in relation to the containers running it

There are so many docker orchestration tools like Kubernetes or Docker Swarm. But, there is a simple tool named Docker Compose. It’s a framework that allows developers to define container-based applications in a single YAML file. This definition includes the Docker images used, exposed ports, dependencies, networking, etc.

Looking at the snippet below, each block of 5 to 20 lines represents a separate service. Docker Compose is a very useful tool and makes application deployment fairly simple and easy.

You can run your application with the

docker-compose

command. The ‘docker-compose’ command takes your Compose file as input and makes sure that your application’s state is what you described in the Compose file (we call this the desired state).

Docker Compose can run your multi-container application on a SINGLE HOST ONLY, it cannot run your application on a computer cluster.

If you want to run your application on a COMPUTER CLUSTER, then you need Docker Swarm or Kubernetes.

Docker Swarm runs multi-container applications, just like Compose does. The key difference is that Swarm schedules and manages your containers across multiple machines, while Compose schedules and manages containers on a single host only.

You can use a standard Compose file to deploy your application to the Swarm. It’s the same Compose file that you use with Compose, but some options are limited to either Swarm or Compose in the Compose file. These are described in the documentation Compose file version 3 reference.

Kubernetes? Kubernetes is based on years of Google’s experience of running workloads at a huge scale in production. As per Kubernetes website, “Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.”

It’s basically an alternative of Docker native swarm. For today, Kubernetes is still leading the docker orchestration market.

--

--