Docker Install
To follow along with the real commands in this course you need Docker on your own machine. The Python models in every lesson run in the browser, so you can read the whole course without installing anything, but containers only really click once you have started a few yourself.
Which edition?
| Your OS | What to install | What you get |
|---|---|---|
| Windows 10/11 | Docker Desktop (uses WSL 2) | GUI, CLI, Compose, a small Linux VM that runs the engine |
| macOS (Intel or Apple silicon) | Docker Desktop | Same, using Apple's virtualization framework |
| Linux (Ubuntu, Debian, Fedora, …) | Docker Engine from Docker's apt/dnf repository | The dockerd daemon and the docker CLI, plus the Compose plugin |
Containers built for Linux need a Linux kernel. On Linux, Docker uses yours directly. On macOS and Windows, Docker Desktop runs a lightweight Linux virtual machine in the background and forwards your commands to it. You rarely notice the VM, except that bind-mounted files can be slower and localhost port publishing goes through a proxy.
Note: Docker Desktop is free for personal use, education and small businesses; larger companies need a paid subscription. Docker Engine on Linux is open source. Podman is a popular alternative with a compatible CLI.
Installing on Ubuntu (outline)
Always follow the current instructions at docs.docker.com, since repository URLs and package names change. The steps look like this:
# 1. add Docker's official package repository and its signing key (see the docs)
# 2. install the engine, CLI, containerd and the Buildx and Compose plugins
sudo apt-get install docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin
# 3. optional: run docker without sudo (log out and back in afterwards)
sudo usermod -aG docker "$USER"Warning: members of the
dockergroup can start a container that mounts the whole host filesystem, so membership is effectively root access. Only add trusted users, or look into rootless mode.
Checking the installation
docker version
docker info
docker compose versionSample output (abridged):
Client:
Version: 28.3.2
API version: 1.51
OS/Arch: linux/amd64
Server: Docker Engine - Community
Engine:
Version: 28.3.2
API version: 1.51 (minimum version 1.24)
Docker Compose version v2.38.2docker version prints two sections because Docker is a client/server system. The CLI (client) talks to the engine (server) over a Unix socket (/var/run/docker.sock) or a named pipe on Windows. If you see the client section but an error like Cannot connect to the Docker daemon, the CLI is installed but the engine is not running.
Client and server: a model
The CLI turns each command into an HTTP request to the engine's REST API. The model below plays both sides, which also shows why the "daemon not running" error appears.
class Engine:
def __init__(self):
self.running = False
self.images = ["hello-world:latest"]
def handle(self, method, path):
if method == "GET" and path == "/version":
return 200, {"Version": "28.3.2", "ApiVersion": "1.51"}
if method == "GET" and path == "/images/json":
return 200, self.images
return 404, {"message": "page not found"}
class Cli:
def __init__(self, engine):
self.engine = engine
def call(self, command, method, path):
if not self.engine.running:
print(f"$ docker {command}")
print(" Cannot connect to the Docker daemon. Is the docker daemon running?")
return
status, body = self.engine.handle(method, path)
print(f"$ docker {command} -> {method} {path} [{status}]")
print(" ", body)
engine = Engine()
cli = Cli(engine)
cli.call("version", "GET", "/version")
engine.running = True # e.g. sudo systemctl start docker
cli.call("version", "GET", "/version")
cli.call("image ls", "GET", "/images/json")$ docker version
Cannot connect to the Docker daemon. Is the docker daemon running?
$ docker version -> GET /version [200]
{'Version': '28.3.2', 'ApiVersion': '1.51'}
$ docker image ls -> GET /images/json [200]
['hello-world:latest']
Post-install checklist
A small script can check the things that most often go wrong after an install. Here it reads a fake description of a machine so you can see each rule; change the values to see other results.
machine = {
"os": "linux",
"kernel": (6, 8),
"docker_group": False,
"daemon_running": True,
"compose_plugin": "v2.38.2",
"free_disk_gb": 7,
}
checks = [
("Linux kernel 4.x or newer", machine["kernel"] >= (4, 0)),
("Docker daemon is running", machine["daemon_running"]),
("User can run docker without sudo", machine["docker_group"]),
("Compose v2 plugin installed", machine["compose_plugin"].startswith("v2")),
("At least 10 GB free for images", machine["free_disk_gb"] >= 10),
]
for label, ok in checks:
print(f"[{'ok' if ok else '!!'}] {label}")
problems = sum(not ok for _, ok in checks)
print(f"{problems} thing(s) to fix")[ok] Linux kernel 4.x or newer
[ok] Docker daemon is running
[!!] User can run docker without sudo
[ok] Compose v2 plugin installed
[!!] At least 10 GB free for images
2 thing(s) to fix
Useful first settings
- Disk space: images and build cache grow over time.
docker system dfshows usage anddocker system prunecleans up stopped containers, unused networks and dangling images. - Resources (Desktop): in Docker Desktop's settings you can give the Linux VM more CPUs and memory.
- Compose: modern Docker includes Compose v2 as
docker compose(with a space). The old Python tooldocker-compose(with a hyphen) is retired.
Test yourself
Why does docker version show both a Client and a Server section?
- Docker has two separate products you must buy
- The CLI is a client that sends API requests to the Docker Engine daemon
- It shows the version of Docker Hub
- One section is for Windows and one for Linux
How does Docker Desktop run Linux containers on macOS?
- macOS has a Linux kernel
- It translates Linux system calls to macOS ones
- It runs a lightweight Linux VM in the background
- It cannot; only Windows containers work
Why should you be careful about adding users to the docker group?
- It slows Docker down
- It is effectively root access to the host
- It disables the build cache
- It removes sudo from the system