🐳docker

In a nutshell, docker or containers are used to run programs in an isolated environment that contains all required dependencies like software, libraries, configuration files, etc.

Containers are nowadays the generally accepted way to bundle, ship, and run software, especially in the server/cloud world. It is a widely accepted standardization between developers, server admins, DevOps, and cloud providers.

It more or less solves the "it worked on my computer..." problem. You run the container on your machine and it contains all the necessary files and dependencies to start it (however, you still need to read the documentation).

Docker is also the name of the company Docker Inc. The term is closely related (and mostly used interchangeably) to containerization. Therefore "docker" in this context will be related solely to the term containerization, not to the company. If the company is meant, it will be explicitly mentioned.


There is a bit more to containers than this simple explanation. In this write down, abstraction is used explain the topic step by step. Page by page, the high level abstraction will be revealed, therefore it can happen that some statement are not completly true. High level abstraction will be marked with an asterix (*) in the text, drawings or images.


Lightweight virtualization

Containers are often compared to virtual machines (VMs) or virtualization in general. They are similar in context. Containers are more "lightweight" in comparison.

The key takeaway is, that for virtual machines there is more or less one additional operating system (OS) in between. Each virtual machine has its dedicated operating system inside. This means the application first communicates with the VM operating system, which then communicates with the host OS or hypervisor which then executes the instruction on the hardware.

Containers communicate in an isolated environment directly with the Host OS. Even if the container itself has a different OS inside, this OS is just an abstraction that talks directly with the Host OS.

For details about containers vs virtual machines see the article from Microsoft: https://learn.microsoft.com/en-us/virtualization/windowscontainers/about/containers-vs-vm.

Key components

Containers have several components.

Dockerfile

The Dockerfile is a file that contains all instructions to generate an Image. The instructions contain all details about the prerequisites, requirements, and dependencies.

As an example for a python application, the Dockerfile contains:

  • instructions for the required base image i.e. OS such as alpine linux

  • instructions to install the required software i.e. python 3.11

  • instructions to install the dependencies i.e. the python requirements (pip install ...)

  • instructions to copy the source code (or build source code) into the Image

Often it is not necessary to write your own Dockerfile, most applications already ship as pre-build docker image. If you want to ship your application, most of the time you can already build on top of pre-build images of your programming language of choice. The most know container image registry is hub.docker.com, where you can find a lot of pre-build images.

For more detailed information about Dockerfiles and how to write them, check out the page:

🐳Dockerfile

Image

The container image is a pre-build bundle (generated from a Dockerfile).

After the build process of the Dockerfile, the image contains all files, dependencies, libraries, etc. to run the application. It is more or less a big archive (i.e. zip file) with all the necessary files to start a Container.

🐳Image

Container

The container is a confined environment to run an application. It can be compared to executables, however the container wraps all content of the executable in its sandbox*. A container always runs a specific Imagewhich defines its use-case/application.

The idea behind the container comes from the cloud/server world. Here, it is important to easily start up multiple applications (containers) at once during high demand (and also stop containers when the load decreases).

By default containers are stateless, meaning if the container i.e. stops due to a crash, all generated data inside the container is also lost. If the data inside a container shall be persistet after a container shutdown, a Volumeis required.

🐳Container

Volume

This section is tbd.

🐳Volumes

Last updated