The Problem Docker Solves: Beginner's Introduction to Docker
Tags: containers, docker, cicd, devops
Published: 2024-05-16 11:54:03

## Introduction

The recent talk of the town - a revolution to how applications are deployed. When developers build and successfully run an application, most times the application fails on deployment to different environments.

Docker takes an application and everything it needs (dependencies and runtime), then puts them in an isolated environment. This makes the application independent of other processes and enables it to run smoothly across different environments (servers). Interesting, isn't it? Let’s dig deeper into that!

This article explains docker, the problems it solves, basic concepts and benefits of using docker.

## The PROBLEM

- Redundant configurations
- Conflicting dependencies (Dependency hell issue)
- Slow deployment
- Scaling

After an application is built, the next step is to deploy to production environments. Each production server is manually configured - installing application dependencies, libraries, which makes the deployment process slow and cumbersome.

To make matters worse, some applications usually require similar dependencies but of different versions leaving us with the hunt of compatible versions of dependencies for these applications. In several scenarios, we’re left with no other option but to use a deprecated version that can support both applications. This issue is popularly known as the Dependency Matrix Hell.

![Fire on applications, with no hope of similar dependencies](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/70u3jxlxeq4zzn7s47pp.png)

Also, applications that perfectly work on a developer’s machine might fail to run on a production environment. Some underlying processes and applications running on the production server makes the production environment incompatible and different, causing the application to fail. This makes the developer yell “It works on my machine!!”.

## The SOLUTION - DOCKER

Docker is an open-source containerization platform. The free availability of docker to a wider audience contributed to the vast adoption of this containerization technology which positively transformed the deployment game in the industry.

Docker allows developers to package an application together with its dependencies, libraries and runtime into lightweight, isolated, self-contained units (containers).

This isolated and self-dependent functionality prevents conflicts with underlying processes (other applications and system processes), and ensures the application runs the same way in any environment. Thereby eliminating the popular “it works on my machine” problem - healing to every developer's headache.

Since the application is packaged with its configuration requirements and runtime, this further eliminates the need to manually configure each production server. All you need on the production server is docker installed!

## Basic Docker Terminologies

### Image

A docker image is a lightweight, independent and standalone package. It contains the application code, dependencies, libraries and runtime. With a docker image, you can easily deploy several containers.

Most images are built upon existing images or parent images. For example, a front-end application image can be built on a httpd-server image which provides server functionality and configurations to the front-end application.

Images are immutable and cannot be modified after creation. Images are built using a dockerfile. Dockerfile is a file with defined steps (instructions) to create a docker image.

### Container

A container is a lightweight, self-sustained unit that runs the application code and the dependencies. It is the running instance of the application created from the docker image.

Containers pick up only the necessary components needed for execution of the application from the docker image. This makes them lightweight, portable, and easy to run across different environments (servers).

### Docker registry

A docker registry is a remote storage that enables distribution of docker images. It serves as a central storage for uploading and downloading images. Docker Hub is the official public registry for Docker images.

Docker Hub provides two types of repositories (storage types):

1. **Public repositories**: Images in this repo are generally available to the public. They are free and open-source images.
2. **Private repositories**: Private repositories are usually created by an organization. Images found here are only accessible by members of the organization.

## Containers Vs Virtual Machines

Both containers and virtual machines are capable of running applications in an isolated environment, but it is important to understand their key differences.

![comparison of utilization of resources in containers to virtual machines](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/in5jtjrqafjs2g9g0ol5.png)

Virtual machines are virtual computers within your physical computer that run a **full guest operating system**. Each virtual machine shares the underlying hardware resources with the host operating system (your personal OS) and other virtual machines. This makes them heavy and compute-resource demanding.

Containers are lightweight, isolated environments that include only the application and required dependencies. Each container **shares the operating system kernel** with the host and other containers. This makes them light-weight and easy to deploy.

## Benefits of Docker

1. **Consistency**: With docker, applications run successfully and behave the same way across different environments from development to production.
2. **Portability**: Containers are lightweight, this makes it easier to deploy applications to several environments and even store the image in docker registries.
3. **Isolation**: Isolation of each container prevents conflicts between containers and host machine, eliminating the occurrence of dependency matrix hell - where different applications require similar dependencies but of different versions.
4. **Collaboration**: since the application runs successfully across all platforms, this will foster collaboration between teams, such as the developers and operations team.
5. **Scalability**: Docker empowers developers to create or destroy several instances of the application in response to user demands.

## Conclusion

With the elimination of ‘it works on my machine problem’ and ‘dependency hell issue’, organizations now experience consistent deployment and efficient scalability, thanks to docker. As Docker clears obstacles in your deployment journey, your applications are only a few commands away from a successful deployment.

I have also written a short story to further help visualize the problem-solving feature of Docker on X (formerly twitter). You can check it out [here](https://x.com/DrInTech22/status/1702760614970499338).