5 min read

Docker in a nutshell

Docker in a nutshell

Docker is a tool for people who work in software engineering. It is used as a platform to run plenty of applications or softwares in their isolated environments.

It is the most widely used container runtime. A container runtime is software that executes containers and manages container images on a node. There are other container runtimes in the ecosystem, such as rkt, containerd, and lxd.

This blog gives a brief insight about Docker and its components. The contents which will be covered in this blog are:                                                                                                             Why do we need Docker                                                                                                              Installation                                                                                                                                    Docker Engine                                                                                                                              Docker Image and Docker Container                                                                                        Dockerfile                                                                                                                                      Docker Compose                                                                                                                          Final Words

Why do we need Docker?

Any application which runs on a computer might be not able to run on a different computer which has same hardware and software configuration. This can be happen to many reasons such as environment issue, installation issue, etc. Docker gives the solution by creating a virtually isolated environment and configuration for any application or software. In general, programmers use docker to avoid unnecessary installations too, to save their disk space.

Installing Docker

Docker can be installed on all platforms like Linux, Mac OS and Windows. On Windows, note that a 64-bit processor and 4GB system RAM are the hardware prerequisites required to successfully run Docker. With addition to that Hyper-V and Containers Windows features must be enabled on Windows. Hyper-V is a Microsoft technology that allows users to create virtual computer environments, and run and manage multiple operating systems on a single physical server.

Go to the official website and download the file. Run that Docker desktop installer exe file.

Docker Engine

Docker engine is the layer on which Docker container runs. It’s a lightweight runtime and tooling that manages containers, images, builds, and more. It runs natively on Linux systems and is made up of:                                                                                              1. A Docker Daemon that runs in the host computer. The Docker daemon is what actually executes commands sent to the Docker Client — like building, running, and distributing your containers
2. A Docker Client is a kind of interface which takes the users' commands and sends it to the Docker Daemon.
3. A REST API for interacting with the Docker Daemon remotely.

Docker Image and Docker Container

Docker image is an immutable file that contains the source code, libraries, dependencies, tools, and other files needed for an application to run. Since a Docker Image cannot be modified or edited, it cannot be run and modified. Docker Image has to be used as base to build the container.

A container is just a running image. Once a container is created, it adds a writable layer on top of the immutable image, meaning it can be now modified. It is a virtualized run-time environment where users can isolate applications from the underlying system. These containers are compact, portable units in which an application start up quickly and easily.  

Images can exist without containers, whereas a container needs to run an image to exist. Therefore, containers are dependent on images and use them to construct a run-time environment and run an application.

Docker has a platform called 'Dockerhub' which act as an application-store, a place where creators have put their 'Docker Images' of their applications. Any image can be run as container from Dockerhub with docker run command.

Source https://hub.docker.com/
Docker run command.

Docker gives the facility to create one's own image. The build command is used to build an image from a Dockerfile, but the command has to be run in the same directory as the Dockerfile. When an image is built, the commands specified in the Dockerfile are executed. The operating system is installed​ along with all the packages required in the Docker container.

Docker build command.

Dockerfile

After installation, it all starts with a script of instructions that define how to build a specific Docker image. This script is called a Dockerfile. The file automatically executes the outlined commands and creates a Docker image.

Example of a Dockerfile

Docker Compose

Docker Compose is a tool that helps us easily handle multiple containers at once. It is a concept when you have the need to use two or more than two applications (containers) at the same time and with dependencies on each other. For Docker Compose, you have to use a Docker Compose file with other related files in one directory as a package. It's like you're creating an application with the help of 2 or more than 2 softwares/applications.                                                                                         Docker Compose works by applying many rules declared within a single docker-compose.yml configuration file.

Example of Docker Compose file

These rules of YAML-file are both human-readable and machine-optimized, provide us an effective way to create a system. We can configure plenty of things in the docker compose file, but main things are version, services, ports, volumes and networks.                                                                                                                                       Version- It defines certain functions or features acquired by                                                              docker-compose file by giving a specific version.                                               Services- This section defines that containers that are to be created.                           Volumes- This section defines the mountings of a project folder or file to the                              docker compose. Volumes are used when one doesn't want to lose                                    application's data associated with the docker, or to save something externally                from the docker.                                                                                                 Ports- This is used to map the container’s ports to the host machine.                             Networks- This section is used to create networks among the containers of the                               docker compose.          

Final Words

Docker makes it easy for developers to quickly create ready-to-run containered applications; and it makes managing and deploying applications much easier. Docker gives the tool for container orchestration too. Container orchestration is all about managing the lifecycles of the containers, especially in large, dynamic environments. There are two popular tools that are used for container orchestration: Docker Swarm and Kubernetes.

References:

1. https://airflow-tutorial.readthedocs.io/en/latest/airflow-intro.html                           2. https://medium.com/swlh/what-exactly-is-docker-1dd62e1fde38                               3. https://www.analyticsvidhya.com/blog/2020/11/getting-started-with-apache-airflow/