Install Docker on Linux
Docker lets you run programs in containers: neat packages with everything a program needs. You don’t install anything separately on your server and you can start, update or remove a program with a single command. That’s why almost all homelabs use it.
What do you need?
- A Linux computer or server: Debian, Ubuntu, Raspberry Pi OS or a virtual machine or LXC container in Proxmox.
- A user with
sudoprivileges and an internet connection. - On Windows or macOS you use Docker Desktop. On a server you install Docker Engine, as shown below.
Option 1: the official Docker source (recommended)
This follows the guide on docs.docker.com. Below is the variant for Debian. For Ubuntu you replace debian in the two addresses with ubuntu.
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/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/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Option 2: the installation script (faster)
Docker also offers a script that does everything at once. That’s useful for a test or a Raspberry Pi. Always read a script first before you run it.
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
Check if it works
sudo docker run hello-world
If you see a message that it worked (“Hello from Docker!”), everything works. You also see the version with docker --version and docker compose version.
Working without sudo
Add yourself to the docker group, log in again and you no longer need to type sudo.
sudo usermod -aG docker $USER
Note: anyone in the docker group essentially has administrator privileges on the server. So only do this for users you trust.
What now?
Read how Docker works and then set up your first services with Docker Compose.