ACLClouds
ACLClouds

How do I install Docker on Debian 12 or Ubuntu 24.04?

Install Docker Engine and Docker Compose from the official repository, on Debian 12 or Ubuntu 22.04 / 24.04, then test the installation with hello-world.

Use Docker’s official repository to get maintained versions, on Debian as on Ubuntu: the docker.io package from Ubuntu’s repositories and the Docker snap lag several versions behind. Avoid scripts copied from an unknown source. The procedure is the same on Ubuntu 22.04 and 24.04; only the repository address changes.

Step-by-step procedure

  1. Prepare the system

    Update Debian and install repository tools and certificates.

  2. Add Docker’s key

    Download the official key into /etc/apt/keyrings then add the Docker repository to the APT sources: download.docker.com/linux/debian on Debian, download.docker.com/linux/ubuntu on Ubuntu.

  3. Install Docker Engine

    Install Docker Engine, the Buildx plugin and Docker Compose.

  4. Test the installation

    Run docker run --rm hello-world, then check that the service starts when the system boots.

  5. Use Docker without sudo

    Add your user to the docker group then log in again; check docker compose version to confirm the Compose plugin is installed.

Official installation on Debian 12

apt update
apt install -y ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
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" > /etc/apt/sources.list.d/docker.list
apt update
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
docker run --rm hello-world

Official installation on Ubuntu 22.04 / 24.04

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
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run --rm hello-world

Limit the size of the logs

cat > /etc/docker/daemon.json <<'EOF'
{
  "log-driver": "json-file",
  "log-opts": { "max-size": "10m", "max-file": "3" }
}
EOF
systemctl restart docker
docker info --format '{{.LoggingDriver}}'

Before you start

Connect with ssh root@IP, replacing IP with the IPv4 address shown in “My services” > your VPS. The initial password is sent to you by email when the VPS is delivered. The commands in this guide are run as root; with another account, put sudo in front of each one.

  • Check the system with cat /etc/os-release: the Docker repository uses the distribution codename, bookworm for Debian 12 and trixie for Debian 13, jammy for Ubuntu 22.04 and noble for Ubuntu 24.04.
  • Remove old unofficial packages if they are present: apt remove docker.io docker-compose podman-docker containerd runc. They conflict with the packages from the Docker repository.
  • The official script curl -fsSL https://get.docker.com | sh installs the same packages in one command. It is fine for a quick test; for a server you maintain over time, the APT repository shows clearly what is installed.

Check that everything works

docker run --rm hello-world must print Hello from Docker!. Then check these two points:

  • systemctl is-enabled docker returns enabled: Docker will start again when the VPS reboots.
  • docker compose version shows the version of the Compose plugin. The command is written with a space.

Good practice

Docker writes its own iptables rules, which are applied before UFW rules. A port published with -p 8080:80 therefore stays reachable from the Internet even if UFW blocks it. For a service that only a reverse proxy on the same VPS should reach, publish it on 127.0.0.1:8080:80.

Without a limit, container logs grow until they fill the disk. The setting below applies to containers created after Docker restarts.

Run a first application with Docker Compose

Once Docker is in place, describe your containers in a compose.yaml file and start them with docker compose up -d. The guide “How do I use Docker Compose on an Ubuntu or Debian VPS?” builds a complete example, WordPress with MariaDB, with the everyday commands, backups, HTTPS and the most common errors.

Frequently asked questions

What should I do if apt shows E: Could not get lock /var/lib/dpkg/lock-frontend?

Another APT operation is running, often the automatic updates started at the first boot of the VPS. Wait a few minutes, check with ps aux | grep -E 'apt|dpkg', then run the command again. Do not delete the lock file: you could corrupt the package database.

Why do I get permission denied while trying to connect to the Docker daemon socket?

You are using an account that is not root and is not in the docker group. Add it with usermod -aG docker deploy, replacing deploy with its name, then close and reopen the SSH session. This group gives root-equivalent rights on the VPS: only grant it to trusted accounts.

What does Cannot connect to the Docker daemon at unix:///var/run/docker.sock mean?

The Docker service is stopped or failed to start. Run systemctl start docker, then read journalctl -u docker -n 50 if the error comes back. A malformed /etc/docker/daemon.json file, for example with an extra comma, is enough to block the start.

Why do I get docker-compose: command not found?

The official repository installs Compose as a Docker plugin, not as a separate program. Replace docker-compose up -d with docker compose up -d in your commands and scripts.

Can I install Docker on Ubuntu with apt install docker.io or the snap?

Technically yes, but Ubuntu’s docker.io package and the Docker snap lag several versions behind and do not include the Compose v2 plugin. Remove them with apt remove docker.io docker-compose or snap remove docker, then follow the Ubuntu block above with the official repository.

Why do I get Package 'docker-ce' has no installation candidate?

APT cannot find a Docker repository that matches the system. Open /etc/apt/sources.list.d/docker.list: the line must point to linux/ubuntu on Ubuntu and linux/debian on Debian, with the right codename (noble, jammy, bookworm or trixie). Fix it, then run apt update again.

What should I do if apt update shows Conflicting values set for option Signed-By?

The Docker repository is declared twice with different keys, often after the get.docker.com script followed by a manual installation. Keep a single file in /etc/apt/sources.list.d/ (docker.list or docker.sources), delete the other one, then run apt update again.