Containerization Introduction

Architecture is basically a container of something. I hope they will enjoy not so much the teacup, but the tea.Yoshio Taniguchi

Photo by Pat Whelen on Unsplash

Docker has taken the world by storm. Initially released in 2013, https://en.wikipedia.org/wiki/Docker_(software) it has grown to be a major contributor to OS-level_virtualization. As stated on the Wikipedia page:

Docker can package an application and its dependencies in a virtual container that can run on any Linux, Windows, or macOS computer. This enables the application to run in a variety of locations, such as on-premises, in public (see decentralized computing, distributed computing, and cloud computing) or private cloud.

Much ink has been spilled on how great Docker is, so I won’t belabor that point. Here https://www.altexsoft.com/blog/docker-pros-and-cons/ is an article that focuses largely on the pros. 

Containers vs Virtual Machines

Virtual Machines such as VMWare https://www.vmware.com/, VirtualBox https://www.virtualbox.org/, and Vagrant https://developer.hashicorp.com/vagrant have been around quite a while. Some distinctions between VMs and Containers are as follows:

VMs Containers
Every OS consumes additional CPU, RAM, disk, etc. All containers share a single host.
VM needs individual patches per OS. Single host OS is easier to manage.
Consumes more resources. Consume fewer resources.
Slow startup. Fast startup.
Full isolation of each VM inside its own OS. Running each container inside of a shared host potentially is less secure.

A diagram:

Virtual Machines vs Containers

While certainly not the first containerization engine, Docker has become one of the more influential. As of this writing Docker Desktop and a few other tools were free for individual developers. Pricing plans for Docker are here: https://www.docker.com/pricing/

The Docker Engine used to just be a daemon and a version of LXC (see https://linuxcontainers.org/) but it has since been modified to the figure below where LXC has been replaced for containerd https://containerd.io/ and runc https://github.com/opencontainers/runc.

Image credit: Docker Deep Dive: Zero to Docker in a Single Book, Nigel Poulton.

Docker on Linux (Ubuntu)

Note: as of this writing Docker is incompatible with Uncomplicated Firewall (ufw) https://wiki.ubuntu.com/UncomplicatedFirewall. See: https://docs.docker.com/engine/network/packet-filtering-firewalls/#docker-and-ufw. If you plan to use a firewall with Docker use iptables https://linux.die.net/man/8/iptables.

To install on Ubuntu 24.04, first ensure exiting docker containers, images, and build caches are gone with: NOTE this is not an undoable operation so if you need any of the stuff in there back it up first!


docker rm -f $(docker ps -aq)
docker rmi -f $(docker images -aq)
docker builder prune -a -f
docker builx prune -a -f

Then update and upgrade Ubuntu:


sudo apt update
sudo apt upgrade

IF necessary, shutdown and restart. I always do just to be safe. Next, remove Uncomplicated Firewall and any docker-related packages if you have any:


sudo apt remove --purge ufw
sudo apt remove --purge docker.io docker-compose-v2 docker-doc podman-docker

Now set up the Docker Engine.


sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

echo   "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" |   sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

To test the Docker Engine:


sudo docker run hello-world

Congratulations, you are running the Docker Engine!

Docker on Windows

Originally developed for Linux exclusively, Microsoft has partnered with Docker to bring Docker to Windows with platforms such as Docker Desktop. We are going to only do Linux in this tutorial, but the instruction for Windows are here: https://docs.docker.com/desktop/setup/install/windows-install/

Windows apps needs a host with a Windows kernel, and Linux apps need some flavor of Linux running under the hood. I have successfully run Docker Desktop with WSL 2, instructions for that are here: https://learn.microsoft.com/en-us/windows/wsl/install.

Docker on Mac

Docker can also run on a Mac via another version of Docker Desktop. Again, that is not covered here but instructions are at: https://docs.docker.com/desktop/setup/install/mac-install/.

Open Container Initiative https://opencontainers.org/
Cloud Native Computing Foundation https://www.cncf.io/
The Moby Project https://mobyproject.org/

Docker Alternatives

Kubernetes https://kubernetes.io/
Podman https://podman.io/
LXC https://linuxcontainers.org/
Rancher: https://www.rancher.com/
Buildah: https://buildah.io/

Credits:

Docker Deep Dive: Zero to Docker in a Single Book, Nigel Poulton.
https://learning.oreilly.com/library/view/docker-deep-dive/9781837028351/