Skip to content

What is Docker and what is it used for?

At the end of Phase 6, the shop’s API keeps its data in PostgreSQL, knows who you are and stops anyone who keeps trying passwords. It works on your computer. This phase’s question is a different one: would it work on someone else’s, or on a server, without an afternoon of installing things?

In this phase you put it in ContainerA program that runs isolated and carries inside everything it needs, with its own files, its own network and its own processes. It isn’t a virtual machine, because it doesn’t start a whole system; it shares the Linux kernel of the machine it runs on. That’s why it starts in less than a second.Go to definition with DockerA program that creates containers and runs them. It has two parts, a daemon that does the work and the docker command you use to ask it, and it works the same on any computer where it’s installed.Go to definition: the API, its database and everything they need, packaged to start the same way anywhere. By the end, the whole shop starts up with one command.

Picture Luis, your partner in the shop, wanting to start the API on his laptop. You hand him the project and tell him “run npm start”. It doesn’t start. To make it work, he has to repeat what you did over three phases, and it isn’t the same on every system:

What he needs On the Mac On Ubuntu and WSL Where you did it
Node 26 nvm nvm, and first libatomic1 with apt: without it, node won’t start Phase 3
The dependencies npm ci npm ci Phase 3
PostgreSQL 18 Homebrew, and a line in ~/.zshrc for the PATH PostgreSQL’s repository, because Ubuntu’s comes with version 16 Phase 5
The shop role and its two databases createuser, without sudo: you are the superuser sudo -u postgres createuser Phase 5
The configuration .env with DATABASE_URL and the secrets, and the migrations The same Phases 5 and 6

That’s five things, each with its versions and its differences. One forgotten step, or a different version, is enough for the API to fail on one computer and not on another. That phrase, “it works on my machine”, is so common that it’s a running joke among people who code.

And it isn’t only Luis. In Phase 8 you’ll rent a server, which starts out empty: you’d have to repeat the whole table there, without a mistake, and again every time something changes.

A container is a program that runs isolated and carries everything it needs inside: its files, its version of Node, its dependencies, even the pieces of the system. What’s on your computer doesn’t affect it, and it doesn’t touch your computer. Docker is the program that creates containers and starts them.

Instead of handing Luis five steps, you hand him the API already packaged, with Node 26 inside. All he needs is Docker.

The analogy

Until the 1950s, loading a ship took days. Every sack, every crate and every barrel had its own shape, and the dockworkers placed them one by one. At every port, all over again.

Then came the shipping container: a steel box of fixed size. What goes inside doesn’t matter, bananas or washing machines. The cranes, ships and trucks of the whole world know how to move that box, and nobody opens it along the way.

A Docker container is that box for a program. Inside goes the API with everything it needs; outside, any computer with Docker knows how to start it.

Where the analogy breaks down

  • A steel box is closed and still. A Docker container is a running program: it starts, it stops and it writes on the screen.
  • From a Docker container you can get many identical copies at once, from the same template. That template is the image, from lesson 1.
  • The boxes on a ship share nothing. Docker containers share the system’s kernel, as you’ll see now, and that’s why their isolation is weaker than a virtual machine’s.
  • “Starts anywhere” has fine print: a Linux container needs a Linux kernel, and one built for one processor doesn’t always work on another.

In lesson 4 of Phase 1 you created a Virtual machineA computer simulated inside another, with its own operating system, its own users and its own files. What happens inside doesn’t touch the computer outside.Go to definition with Multipass: a simulated computer, with its own whole Ubuntu. A container also gives you an isolated Linux, but inside it’s something else.

Every system has a kernel: the part that talks to the computer’s hardware and shares time among the programs, as you saw in lesson 6 of Phase 1. A virtual machine boots its own kernel. A container has no kernel: it uses the one of the system it runs on. It’s one more ProcessA running program. When you start a server, the operating system creates a process that stays alive waiting for requests.Go to definition, like the ones in lesson 5 of Phase 1, to which the kernel shows only its own files, its own network and its own processes.

Virtual machine (Multipass) Container (Docker)
Kernel Its very own The one of the system it runs on, shared
What starts A whole operating system A program
Time to start Tens of seconds Less than a second
Size Gigabytes From a few megabytes
Isolation Strong: another simulated computer Weaker: processes kept apart by the same kernel

And on a Mac or on Windows, which have no Linux kernel? Docker Desktop starts a small virtual machine with Linux, without you seeing it, and all your containers share its kernel. On Linux it isn’t needed: containers use your own system’s.

You’ll check this at the end of this introduction, with Docker already installed.

  1. Containers
  2. Layers
  3. Dockerfile
  4. Multi-stage
  5. Volumes
  6. Networks
  7. Compose
  8. Registries

The first two teach you how Docker works, with test containers. From the third one on, your project gains new files, with its downloadable folder as in the earlier phases:

Lesson What the shop gains Folder
1. Containers Nothing yet: you start nginx in a container —
2. Layers Nothing: you understand how an image is built, with a lab —
3. Dockerfile The API in a container 32-dockerfile
4. Multi-stage A small image that doesn’t run as root and doesn’t carry your secrets 33-small-image
5. Volumes PostgreSQL in a container, with data that survives —
6. Networks The API talks to PostgreSQL by its name —
7. Compose The API, PostgreSQL and Redis with one command; the rate limit, shared in Redis 34-compose
8. Registries The image published to a registry and pinned by its fingerprint —

The API doesn’t change in the whole phase: what changes is how it’s packaged and how it starts. The only exception is the rate limit from lesson 8 of Phase 6, which in lesson 7 starts keeping its count in Redis.

Everything is done with Docker, on your computer. From lesson 3 you work on your project, in ~/backend-course/phase-3/shop-api.

  • On Windows, everything is done in WSL, as since Phase 0, with the Docker Desktop integration you turn on below.
  • Your PostgreSQL from Phase 5 can keep running. When a container needs its port, 5432, lessons 4 and 5 tell you how to stop it.
  • Ports, only on your computer. When a container opens a port, you’ll put 127.0.0.1 in front of it. Lesson 6 explains why.
  • The outputs were captured with Docker Engine 29. The ids, the images’ fingerprints, their sizes and the times will be different on your computer.

Docker has two pieces: the engine (Docker Engine), which creates the containers, and the docker command, with which you ask it to. How they’re installed depends on your system.

Docker Desktop is an app that brings the engine inside its Linux virtual machine, the docker command and a window to see your containers. You install it like any other app, from Docker’s website:

  • On the Mac: Install Docker Desktop on Mac. Choose the installer for your processor (Apple or Intel), drag Docker to Applications and open it. The first time, it asks you to accept its terms: without that, it doesn’t start.
  • On Windows: Install Docker Desktop on Windows. It needs Windows 10 22H2 or Windows 11 23H2, or later, and WSL 2, which you already have. Leave the option to use WSL 2 checked. Then, in Settings › Resources › WSL Integration, check that your Ubuntu is turned on: that way the docker command works inside your WSL terminal (Docker’s guide).

With Docker Desktop, don’t also install Docker Engine inside WSL: the two at once clash.

On Linux, Docker is installed like the PostgreSQL of Phase 5: with apt, from Docker’s own repository, because Ubuntu’s comes with an older version under another name. On WSL, do this only if you don’t use Docker Desktop (for example, because of the license).

First, the key Docker signs its packages with. These are the commands from Docker’s guide for Ubuntu:

The Docker repository's key

Ventana de terminal
sudo apt update
sudo apt install -y 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
  • The first two update the catalog and install curl and the certificates to download over HTTPS, if you didn’t have them.
  • install -m 0755 -d creates the /etc/apt/keyrings folder, where apt keeps the keys of other repositories.
  • curl -fsSL … -o downloads Docker’s public key to that folder, without writing anything on the screen.
  • chmod a+r lets every user read it, with the permissions from lesson 4 of Phase 1.

Then, where the repository is:

Add Docker's repository

Ventana de terminal
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt update

What you will see:

Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: noble
Components: stable
Architectures: arm64
Signed-By: /etc/apt/keyrings/docker.asc
Get:1 https://download.docker.com/linux/ubuntu noble InRelease [48.5 kB]
Get:2 https://download.docker.com/linux/ubuntu noble/stable arm64 Packages [80.4 kB]
…
Reading package lists...

tee writes every line up to EOF to the file, and also on the screen. The two $(…) fill themselves in: your Ubuntu’s name (noble, 24.04) and your processor (arm64; on most PCs, amd64). Signed-By says which key to check each package with.

Look at the Get: lines from download.docker.com: apt already reads Docker’s catalog. If you see NO_PUBKEY or not signed, the key is missing: repeat the previous step. We trimmed the output (…).

Now, Docker:

Install Docker Engine

Ventana de terminal
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

What you will see:

…
Setting up containerd.io (2.4.1-2~ubuntu.24.04~noble) ...
…
Setting up docker-ce-cli (5:29.9.0-1~ubuntu.24.04~noble) ...
…
Setting up docker-ce (5:29.9.0-1~ubuntu.24.04~noble) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /usr/lib/systemd/system/docker.socket.
…

That’s five packages:

  • docker-ce, the engine: a DaemonA program that keeps running on its own, with no window or terminal, waiting to do its job. Web servers are daemons, and many have a d at the end of their name.Go to definition, dockerd, that creates and watches over the containers.
  • docker-ce-cli, the docker command.
  • containerd.io, the piece the engine uses underneath to start each container.
  • docker-buildx-plugin builds images (lesson 3) and docker-compose-plugin adds docker compose (lesson 7).

The Created symlink lines say that the engine is set up as a systemd service, which starts on its own when the machine boots, like nginx in lesson 6 of Phase 1. We captured the output in an Ubuntu 24.04 container, where the service can’t start: we removed two lines that only show up there. Your versions may be newer.

Check that it’s running with sudo systemctl status docker, as you did with nginx: look for Active: active (running). If it says inactive, start it with sudo systemctl start docker.

Now try Docker with your user, without sudo:

Docker without sudo, not yet

Ventana de terminal
docker run hello-world

What you will see:

permission denied while trying to connect to the docker API at unix:///var/run/docker.sock

The docker command doesn’t create containers itself: it asks the engine to. It talks to it through /var/run/docker.sock, a Unix socket: a file through which two programs on the same machine talk, as through a port, but without a network. Only root and the docker group can use that file, and you’re not in it.

The installation created the docker group, empty. Add yourself with usermod, from lesson 4 of Phase 1, and open a shell that already has it:

Join the docker group

Ventana de terminal
sudo usermod -aG docker $USER
newgrp docker
id

What you will see:

uid=1001(ana) gid=995(docker) groups=995(docker),1001(ana)

usermod -aG docker adds you (-a, append) to the docker group (-G) without taking you out of the others. A new group only counts in new sessions: newgrp docker opens a shell that already has it, and that’s why id shows it as your main group (gid).

For it to count in all of them, log out and back in, as Docker’s guide asks; on WSL, type wsl --shutdown in PowerShell, like the wsl --install from Phase 0, and open “Ubuntu” again. After that, your main group is ana again, with docker in the list.

Look for docker in id. Your numbers will be different, and you’ll see more groups, like sudo.

With Docker installed, on the Mac, on Windows or on Linux, everything works the same from here on. First, check that the docker command reaches the engine:

Is Docker there?

Ventana de terminal
docker version

What you will see:

Client: Docker Engine - Community
Version: 29.9.0
API version: 1.56
Go version: go1.26.9
Git commit: f415da8
Built: Thu Oct 8 20:37:09 2026
OS/Arch: linux/arm64
Context: default
Server: Docker Engine - Community
Engine:
Version: 29.9.0
API version: 1.56 (minimum version 1.40)
Go version: go1.26.9
Git commit: a5b58c9
Built: Thu Oct 8 20:37:09 2026
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v2.4.1
GitCommit: f2551031d7276a770f65f98c9b52e57e7dad07e8
runc:
Version: 1.5.2
GitCommit: v1.5.2-0-g29dd3dc2
docker-init:
Version: 0.19.0
GitCommit: de40ad0

Two programs show up, because Docker is two:

  • Client is the docker command you type. Its OS/Arch is your system and your processor.
  • Server is the engine, and below it, the pieces it uses: containerd and runc, which creates each container.
  • API version: the client talks to the engine through an API, like the ones in Phase 4, and both have to understand the same version.

The output is from Ubuntu. On the Mac, the client says darwin/arm64 and Context: desktop-linux, and the Server line says Docker Desktop and its version. But the engine says linux: it runs in Docker Desktop’s virtual machine.

If you only see Client and then failed to connect to the docker API, the engine isn’t running: open Docker Desktop, or start it with systemctl on Linux. If it says permission denied, you’re missing the docker group.

Now, your first container:

Hello, Docker

Ventana de terminal
docker run hello-world

What you will see:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
58dee6a49ef1: Pull complete
c3bdf82c34d1: Download complete
Digest: sha256:5e23090353324d887c48ad5e5c56d294eab81588df9605b07d1afe895f9cc8f8
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(arm64v8)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/

Word by word:

  • docker is the client.
  • run asks the engine to create a container and start it.
  • hello-world is the Docker imageA read-only template with the files a program needs (the program itself, its libraries and a minimal system) and the command to start it. You can start as many containers as you want from one image, and none of them changes it.Go to definition it comes from: the template with the program inside.

The output has two parts. The first six lines are Docker’s, as it prepares the container:

  1. Unable to find image 'hello-world:latest' locally: you don’t have that image on your computer. latest is the tag Docker adds when you don’t give one (lesson 8).
  2. Pulling from library/hello-world: the download from Docker Hub, the public catalog of images. library/ is the folder of the official images.
  3. The two lines with a code in front are the pieces of the image, which download separately. Lesson 2 tells you what they are.
  4. Digest: sha256:… is the image’s fingerprint: a HashA short, fixed-size summary calculated from some data, like a fingerprint. The same data always gives the same hash, and the smallest change gives a completely different one. Git calls each commit by its hash.Go to definition of its contents, like the one that names each Git commit. Lesson 8 uses it to pin versions.
  5. Status: Downloaded newer image: the image is now on your computer.

The rest is written by the program inside the container. Its four steps are what just happened: the client talks to the engine, the engine downloads the image, creates a container and passes you what the program writes. (arm64v8) is the processor it was downloaded for: on most PCs you’ll see amd64.

After writing, the program ends, and the container stops with it: a container lives as long as its program does. Run the command again: this time it downloads nothing, and Hello from Docker! comes out right away. The image was already there.

If instead you get failed to connect or permission denied, go back to the explanation of docker version.

Now you can check what you read earlier: that containers use someone else’s kernel. uname -sr prints the system’s name and its kernel version. Ask your Mac and two containers for it, one with Ubuntu and another with Alpine, another version of Linux:

Which kernel is underneath?

Ventana de terminal
uname -sr
docker run --rm ubuntu:24.04 uname -sr
docker run --rm alpine:3 uname -sr

What you will see:

Darwin 25.6.0
…
Linux 6.8.0-117-generic
…
Linux 6.8.0-117-generic

docker run accepts a command after the image’s name: the container runs that command instead of its own, and ends. --rm deletes it when it ends; lesson 1 tells you why that’s a good idea.

The Mac says Darwin, its own kernel. The two containers, with different systems, say the same Linux kernel: the one of the virtual machine where Docker runs. We captured the output on a Mac with a different virtual machine; with Docker Desktop, yours usually ends in linuxkit, the minimal Linux its virtual machine carries. On Linux and on WSL, the containers say the same as your uname -sr, because they share your system’s kernel.

The first time, each docker run downloads its image, with lines like the ones from hello-world: we removed them (…). Your versions will be different.

Before lesson 1, check that you have everything:

  • docker version shows Client and Server, with no errors.
  • docker run hello-world prints Hello from Docker!.
  • On Linux, it works without sudo, because you’re in the docker group.
  • On Windows, you do it in your WSL terminal, with Docker Desktop’s integration turned on.

Start with lesson 1, “Containers”: you’ll learn what makes an image different from a container, and you’ll start the first one that serves a web page.

phase-7 · introduction