“Why, What, How” Series : Docker — Part 1

Less Tech, more Common Sense ; Less Jargon , more Logic.

PRANJAL BIYANI
6 min readSep 22, 2021

Build. Run. Ship. Repeat!

Let’s start with — Why Docker ?

Image Credit : ThreatStack.com

If you’ve ever built, been part of, managed or invested in an application, tool or product that is mildly complicated or more, in terms of choice of programming language, packages, third-party libraries, OS and development environment, YOU KNOW THE PAIN I’M GOING TO TALK ABOUT!

Exactly!

Imagine working in large team of Software Engineers, Cloud Developers and Data Scientists. The issues you’d be spending most of your productive time resolving will be because of “software collaboration inconsistency” across the team.
Just to set context, every popular and intensively used tool gets updated at least once in every 3–6 months, and every product, even the basic ones require at least 10–20 tools/packages each with their own versions regularly updated. Now just think of the possible combinations of versions!

Coming from a diversely talented team myself, where we all knew how to get the job done, but we were working on different machines with different Operating Systems, different versions of the same programming language, associated packages and tools.

The moment we started aggregating our work ( basically code ) and putting it all together in the Product repository, we faced severe challenges in terms of delays due to mismatched versions of packages, bugs, dependency issues, uninstalled libraries and variety of programming environments

IC : memegenerator.com

This led to the demand ( it was a requirement ) of a tool that would ensure easy replication of a common environment usable for development across team members. It should also facilitate easy and fast installation, execution of this combined environment to multiple machines when finally deployed on the cloud and portability.

Please welcome : Docker !

IC : codefresh.com

Let’s answer : What is Docker ?

Docker is a tool that facilitates OS-level virtualisation to deliver ( develop, ship and deploy ) software as packages called containers that can be consolidated to run on different machines. It simplifies and accelerates development and deployment workflows.

Oh, Sorry! I promised NO JARGON! Allow me to simplify -

Docker enables you to take a working piece of code from a local/personal computer and wrap/transform it into a file ( Docker Image ) that can be shared with other users of the code. Other users of the code can use this file and docker to build an exactly same environment ( Docker Container ), where everything worked seamlessly, on their machines irrespective of what OS, package/library versions they would have previously installed.

Image by Author

That’s it ? No, there’s more, Hang in there!

Let’s breakdown the key technical terms and dive deeper —

  • Dockerfile
  • Docker Image
  • Docker Container
  • Docker Hub
IC : saggie.com

Dockerfile —

A file that contains set of build instructions ( ex : install particular version of a package ), running which creates a docker image. It ensures step by step installation of all requirements to replicate the exact environment in which the code was built and worked seamlessly.

Docker Image —

Upon successful sequential execution of all instructions from a dockerfile, a Docker Image is generated. A Docker Image is basically packaged software, which can be run in any machine irrespective of its OS, hardware, brand etc. using Docker. It contains application code, libraries, tools, dependencies and other files needed to make the application run. Most importantly, it is lightweight and standalone.

Docker Container —

It is the standardised unit deployed (run ) using Docker Image of the particular application. A container is basically the running / deployed version of the Docker Image created using the Dockerfile, functioning independently and encapsulated with all the requirements.This container could be running on the Cloud or on local machines that originally may not have fulfilled the requirements to run the application. Most importantly, more of these containers can be replicated and run based on business requirement, and its super fast!

Docker Hub —

Docker Hub is the registry ( “container image” library ), commonplace for developers to share their containers, open source projects with the community. This repository holds all the versions of all the libraries, packages and tools that you would need to build applications. This is from where docker pulls the required installation files every time a user builds a container using an existing Docker Image. It is regularly updated with newer versions launched, stores older versions and maintains records. It is fundamentally a collection of containers.

Just like GitHub is a collection of code repositories where we share our code, DockerHub is a container repository where we share our containers

IC : morioh.com

What differentiates Docker from Virtual Machine based tools from Oracle ( VirtualBox ) and VMWare Player ?

This is where Docker solved a pressing problem and revolutionised the lives of DevOps, Engineering and Product Teams in 2013. Although both Virtual Machines ( VM’s) and Docker both provide virtualisation, but Docker beats VM’s in more ways than one, to understand better, let’s visualise how both VM’s and Docker function and virtualise.

IC : https://nesi.github.io/

Your infrastructure might be your local personal computer, on premise or cloud, each having its own hardware that is used for processing data and running applications. To set up multiple Virtual Machines on your infrastructure, the most significant overhead is the installation of Guest OS ( personal operating system, which is obviously a large file ) for each and every VM created. VM’s use Hardware-level process isolation. This adds to Virtual machines being too heavy and only linearly scalable, the more you want in terms of output, more resources need to be added. An additional inefficiency is added due to the fact that VM’s need permanently allocated resources which might be underutilised in case a VM is not in use for some time. Considering the cost of cloud instances in terms of usage per hour, we would want resources to be allocated dynamically based on demand.

On the other hand, Docker uses OS level process isolation ,is lightweight, scalable and fast.

  • Light weight — They use the host operating system and don’t require an explicit OS of their own
  • Scalable — Multiple docker containers can run on the same machine using the same host OS and resources will be shared and managed by the Docker Engine.
  • Fast and Portable — Since dockers don’t need to install their own OS, booting a docker container is pretty fast and takes a few seconds, where it takes minutes for a VM. Scalability for high performance systems is enhanced with fast boot speeds.

But, that’s not all, Docker has it’s own drawbacks when we consider security of our applications —

  1. Since Virtual Machines don’t share the OS, they are strongly isolated and secure compared to containers
  2. Access to a single VM does not affect other VM’s, whereas access to a single container can give access to all of them.

Well, I want to talk more about Docker and how it streamlines the path from development to deployment for developers and Engineers, how I use it for my application development, but let’s get our hands dirty first. In the next part of this article, I will take you through a simplistic step-by-step implementation of Docker on a basic “Hello World” application, containerise it, so you can use it as well.

The “Why, What, How” Series is a complete MLOps / DevOps content pool that I am building to share my experience of building an AI Product from scratch. Follow along, and have a good day! Cheers!

“Why, What, How” Series :Docker — Part 2 : Coming Soon….

--

--

PRANJAL BIYANI

Create or Find problems 1st ; Solve or Fix problems 2nd. Learn on the way.