Dockers and Dockerization.

Dockers and Dockerization.

Dockers and Dockerization.

 What is a Container and why do we need it?

Have you ever had the problem where your python code (or any other code) works fine on your computer but when your friend tries to run the exact same code, it doesn’t work? If your friend is repeating the exact same steps, they should get the same results right? The one-word answer to this is the environment. Your friend’s Python environment is different than yours.

What does an environment include? → Python (or any other language you have used) and all the libraries and dependencies with the exact versions using which application was built and tested.

If we can somehow create an environment that we can transfer to other machines (for example: your friend’s computer or a cloud service provider like Microsoft Azure), we can reproduce the results anywhere. Hence, a container is a type of software that packages up an application and all its dependencies so the application runs reliably from one computing environment to another.


This is the most intuitive way to understand containers in data science. They are just like containers on a ship where the goal is to isolate the contents of one container from the others so they don’t get mixed up. This is exactly what containers are used for in data science.
Now that we understand the metaphor behind containers, let’s look at alternate options for creating an isolated environment for our application. One simple alternative is to have a separate machine for each of your applications.

(1 machine = 1 application = no conflict = everything is good)

Using a separate machine is straight forward but it doesn’t outweigh the benefits of using containers since maintaining multiple machines for each application is expensive, a nightmare-to-maintain and hard-to-scale. In short, it’s not practical in many real-life scenarios.

Another alternate for creating an isolated environment are virtual machines. Containers are again preferable here because they require fewer resources, are very portable, and are faster to spin up.


Can you spot the difference between Virtual Machines and Containers? When you use containers, you do not require guest operating systems. Imagine 10 applications running on a virtual machine. This would require 10 guest operating systems compared to none required when you use containers.

I understand containers but what is Docker?

Docker is a company that provides software (also called Docker) that allows users to build, run and manage containers. While Docker’s container are the most common, there are other less famous alternatives such as LXD and LXC that provides container solution.
In this tutorial, we will use Docker Desktop for Windows to create a container that we will publish on Azure Container Registry. We will then deploy a web app using that container.

Docker Image vs. Docker Container

What is the difference between a docker image and a docker container? This is by far the most common question asked so let’s clear this right away. There are many technical definitions available, however, it is intuitive to think about a docker image as a mold based on which container is created. An image is essentially a snapshot of container.
If you prefer a slightly more technical definition then consider this: Docker images become containers at runtime when they run on a Docker Engine.

Docker is a container management tool, which packages the application code, configuration, and dependencies into a portable image that can be shared and run on any platform or system. With docker, we can containerize multiple apps and run them on the same machine/system, as all will share the same services of the operating system kernel, they use fewer resources than virtual machines(VMs).

A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings.

Container images become containers at runtime and in the case of Docker containers – images become containers when they run on Docker Engine.

Breaking the hype:

At the end of the day, docker is just a file with a few lines of instructions that are saved under your project folder with the name “Dockerfile”.
Another way to think about docker file is that they are like recipes you have invented in your own kitchen. When you share those recipes with somebody else and they follow the exact same instructions, they are able to produce the same dish. Similarly, you can share your docker file with other people, who can then create images and run containers based on that docker file.

Docker file

A simple file that consists of instructions to build a Docker Image. Each instruction in a docker file is a command/operation, for example, what operating system to use, what dependencies to install or how to compile the code, and many such instructions which act as a layer.

The best part is all layers are cached and if we modified some instructions in the Docker file then during the build process it will just rebuild the changed layer.

A sample Docker file will look as below

  • FROM creates a layer from the base image, here we have used ubuntu:18.04 Docker image
  • WORKDIR specifies the working directory
  • COPY adds files from your Docker client’s or host system current directory, here we are adding current directory files to the container’s app directory
  • RUN specifies what commands to run within the container, here running pip command to install dependencies from requirements.txt file
  • EXPOSE specifies which port to expose our application, here it’s 5000
  • CMD specifies what command to run at the start of the container.
Docker Image
Once a docker file is created, we can build a docker image from it. Docker Image provides the execution environment for an application, bundling all necessary code, config files, and dependencies.

A Docker image consists of read-only layers each of which represents a Dockerfile instruction. The layers are stacked and each one is a delta of the changes from the previous layer.

We can build a docker image with a docker file using the docker build command.

Once the docker image is built we can test it using the docker run command, which will create a container using the docker image and runs the application.

Docker Registry
Once the docker image is built and tested, we can share it with others so that they can use our application. For that, we need to push the docker image to the public docker image registry such as Docker Hub, Google Container Registry(GCR), or any other registry platforms.

We can also push our docker images to private registries to restrict the access of the docker image. The docker images are deployed in our required cloud platforms.

                                                      ***Thank You***

0 Response to "Dockers and Dockerization."

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel