From point A to point B
Point A: you have heard about Docker and containers, maybe you have even copied a docker run or two, but you are not sure what problem they solve or what happens inside. Point B: by the end of this chapter you will be able to explain why containers exist, how they differ from a virtual machine and what an image is, and you will have Docker installed and running on your Linux machine.
Everything that comes later in this route, Kubernetes included, builds on this foundation. That is why Docker comes right after Linux in the route.
- Why you need Docker: the matrix from hell
- What a container is and what it isolates
- Containers vs virtual machines
- Image vs container: blueprint and instance
- Docker in DevOps: build, ship, run
- Docker editions today
- Installing Docker on Ubuntu, two ways
- The golden rule: a container lives as long as its process
Why do you need Docker?
Picture an application with four parts: a web server, a database, a messaging system and an orchestration tool. Each part needs certain libraries and certain operating system versions. What one part requires, another one breaks.
Without containers, three problems show up that every team recognises:
- Compatibility and dependencies. Upgrading a library for one component can take another one down. Every change means checking the whole stack again.
- Setups that take days. Every new team member has to build their environment step by step, with long instructions and plenty of ways to get it wrong.
- Different environments. Development, test and production are never identical. The classic “it works on my machine” is born here.
That web of incompatible combinations is known as the matrix from hell.
Without containers, any combination of component and environment can fail. With containers, each piece travels with its dependencies and behaves the same everywhere. Diagram: The House of Routing.
Docker solves this with a simple idea: package each component with everything it needs and run it in isolation. If the host has Docker, the package works.
What is a container?
A container is a completely isolated environment. It has its own processes, its own network and its own mounted filesystem, but it shares the kernel of the host operating system.
Each container sees only its own processes, network and mounts. Underneath, they all use the same Linux kernel. Diagram: The House of Routing.
That isolation is not magic: two Linux kernel features provide it. Namespaces decide what each container can see (processes, network, mounts, users). cgroups limit how much it can consume (CPU, memory, disk I/O).
Containers existed before Docker; LXC, for example, already offered them. But they were hard to set up. Docker, which relied on LXC in its early versions, made them easy to use with a single tool and a common image format.
Sharing the kernel has consequences
Ubuntu, Debian, Fedora and CentOS all use the same Linux kernel; what changes is the libraries and tools. That is why an Ubuntu host can run a container based on Debian or Fedora: the image brings its own libraries and uses the host's kernel.
Containers vs virtual machines
A virtual machine virtualises hardware: a full guest operating system, with its own kernel, runs on top of a hypervisor. A container only isolates processes on top of the host's kernel.
Virtual machines carry an operating system per application; containers share the kernel. Diagram: The House of Routing.
| Virtual machine | Container | |
|---|---|---|
| Typical size | Gigabytes | Megabytes |
| Start-up | Minutes | Seconds |
| Kernel | Its own, one per VM | Shared with the host |
| Isolation | Stronger: no shared kernel | Lighter, but enough for most cases |
| Can mix operating systems | Yes, Windows and Linux on the same host | Only those compatible with the host kernel |
It is not one or the other. In the cloud it is very common to run containers inside virtual machines: the VM brings strong isolation and the container brings lightness and portability.
Image vs container
These two terms get mixed up a lot. The difference is simple:
- Image: the blueprint. A read-only template with the application and everything it needs, ready to run.
- Container: a running instance of that image. From one image you can start one container or a hundred, each isolated from the others.
Thousands of ready-made images live in public registries such as Docker Hub: operating systems, databases, web servers. You can also build your own.
docker pull nginx:alpine # download the image
docker images # list local images
docker run -d nginx:alpine # create and start a container from it
docker ps # list running containers
Docker in DevOps
In the past, development handed over the application with an installation guide and operations tried to reproduce the environment. With Docker, development hands over a Dockerfile and an image. That image works the same on any host with Docker.
Build once, publish to a registry and run anywhere. Diagram: The House of Routing.
- Fast deployments: a container starts in seconds and is replaced just as quickly.
- Small, independent pieces: each service gets its own container, which makes microservices easier to work with.
- Portability: the same image moves from the laptop to test and to production unchanged.
- A shared language: the Dockerfile documents how the application is built, and development and operations share it.
Docker editions today
For years people talked about two editions: Community, free, and Enterprise, paid and officially supported. The picture has changed, and it is worth being clear about it:
| Product | What it is | Licence |
|---|---|---|
| Docker Engine | The engine that runs on Linux: daemon, API and CLI. It is what you install on servers. | Open source and free |
| Docker Desktop | A graphical application for Windows, macOS and Linux. It bundles the engine, Compose and a light VM when needed. | Free for personal use, education, non-commercial open source projects and companies with fewer than 250 employees and less than 10 million US dollars in annual revenue. Beyond that, it requires a paid subscription. |
| Former Docker Enterprise | In November 2019, Mirantis bought Docker's Enterprise business, which continues today under the Mirantis brand. | Commercial, from Mirantis |
Installing Docker on Ubuntu
Here are two paths. For practice, the first one is the most direct.
Option 1 · Docker Engine with the official script
First, remove old or unofficial packages that could clash with the installation:
for pkg in docker.io docker-doc docker-compose docker-compose-v2 docker-buildx podman-docker containerd runc; do
sudo apt-get remove -y $pkg
done
Then download the installation script. The --dry-run option shows you the steps without running them; review them before running it for real:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh --dry-run # only shows what it would do
sudo sh ./get-docker.sh # installs Docker Engine
sudo docker run hello-world # smoke test
If you see Hello from Docker!, the engine downloaded an image, created a container and ran it. It works.
apt, as its documentation describes.Using Docker without sudo, wisely
To avoid typing sudo before every command, add your user to the docker group:
sudo groupadd docker # it may already exist
sudo usermod -aG docker $USER
newgrp docker # apply the change in this session
docker run hello-world
docker group is equivalent to root privileges on that machine. Do it in your lab; on shared servers, think carefully about who gets that access.Option 2 · Docker Desktop for Linux
If you prefer a graphical interface, download the .deb package from Docker's documentation and install it:
sudo apt-get update
sudo apt install ./docker-desktop-amd64.deb
systemctl --user start docker-desktop
At the end, apt may show an error about installing a downloaded package; the documentation says you can ignore it. Remember to check the Docker Desktop licence if you will use it at a company.
The golden rule: a container lives as long as its process
A container is not a virtual machine that stays switched on. It is designed to run one main process, and it exists as long as that process is alive. When the process ends, the container stops.
The ubuntu image starts bash by default; with no terminal attached, bash ends right away and so does the container. Diagram: The House of Routing.
Try it yourself:
docker run ubuntu # starts and ends instantly
docker ps # not listed: it is no longer running
docker ps -a # here it is: status Exited (0)
docker run -d ubuntu sleep 300 # the main process lasts 5 minutes
docker ps # now it is Up
docker run -it ubuntu bash # or step in with an interactive terminal
exit # leaving bash stops the container
That is why an image like nginx keeps running: its main process is a web server that does not end.
Challenge
Answer before you open the solution. Getting it wrong here is the cheapest way to learn.
1. What do all containers running on the same host share?
The operating system kernel. Processes, network and mounts are isolated for each container; the kernel is common.
2. You have an nginx image. How many containers can you create from it?
As many as you need. The image is the read-only template; each container is an isolated instance created from it.
3. You run docker run ubuntu and the container does not show up in docker ps. What happened?
Its main process ended. bash started without a terminal and exited; the container is now in the Exited state. You can see it with docker ps -a.
4. Why should you not add just any user to the docker group?
Because that group grants privileges equivalent to root on the host. It is convenient in a lab, but a risk on shared servers.
What you take away
- Docker was born to end dependency problems and “it works on my machine”.
- A container isolates processes, network and mounts, and shares the host's kernel.
- A VM virtualises hardware; a container, processes. They complement each other.
- The image is the blueprint; the container, a running instance.
- Docker Engine is free and open source; Docker Desktop has licence conditions.
- A container lives as long as its main process lives.
In the next chapter we move to day-to-day practice: the basic Docker commands to create, list, stop and remove containers and images.
Official resources
- What is Docker?docs.docker.com
- Install Docker Engine on Ubuntudocs.docker.com
- Linux post-installation steps for Docker Enginedocs.docker.com
- Install Docker Desktop on Ubuntudocs.docker.com
- Docker Desktop license agreementdocs.docker.com
- Docker Hubhub.docker.com
- Open Container Initiativeopencontainers.org
- Install Docker Desktop on Windowsdocs.docker.com
Source and credits. Chapter written from Jesús Espinoza's study notes on KodeKloud's Docker for Absolute Beginners course (December 2024). Text drafted with AI assistance; original diagrams by The House of Routing. Technical details were checked against the official Docker documentation.