Chapter 6 · 6.1
Installing Docker from the official source
With Docker you run apps in containers: each with everything it needs, separate from the rest of your server. For the recipes in chapter 7 you need Docker and the docker compose plug-in.
Adding Docker's package source
These are the steps from Docker's documentation for Debian. Make a snapshot first (see Snapshots: a safety net for every major change).
anna@web1:~$ sudo apt update
anna@web1:~$ sudo apt install ca-certificates curl
anna@web1:~$ sudo install -m 0755 -d /etc/apt/keyrings
anna@web1:~$ sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
anna@web1:~$ sudo chmod a+r /etc/apt/keyrings/docker.asc
anna@web1:~$ sudo nano /etc/apt/sources.list.d/docker.sources
Put this in that file:
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: trixie
Components: stable
Architectures: amd64
Signed-By: /etc/apt/keyrings/docker.asc
Suites takes the codename of your version: trixie for Debian 13, bookworm for Debian 12. On Ubuntu the URL is https://download.docker.com/linux/ubuntu (for the key too) and the codename is, for example, noble for 24.04. You can see your codename with grep VERSION_CODENAME /etc/os-release.
Installing and testing
anna@web1:~$ sudo apt update
anna@web1:~$ sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
anna@web1:~$ sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
anna@web1:~$ docker compose version
Docker starts automatically, also after a reboot. If you previously installed the docker.io or docker-compose package from Debian or Ubuntu, remove it first: mixing them causes conflicts.
On AlmaLinux and Rocky Linux follow the steps for RHEL at docs.docker.com/engine/install.
sudo or the docker group?
In many places you'll read that you should add yourself to the docker group. Be aware that this group gives just as much power as root. In this manual we type sudo docker. That way there is only one door to root, and it has a password.
Please note: Automatic updates (see Updates and automatic updates) don't update packages from Docker's source by default. Run sudo apt update && sudo apt upgrade regularly, or add the source to your automatic updates.
