Skip to main content

Installing Docker on Debian

Warning: Do not directly install Docker using apt commands without first configuring the Docker APT repository.

Prerequisites

System Requirements

Docker supports the following versions of Debian operating systems:

  • Debian Bookworm 12 (stable)
  • Debian Bullseye 11 (oldstable)

Uninstall Old Versions

Before you can install Docker Engine, you need to uninstall any conflicting packages.

Distro maintainers provide unofficial distributions of Docker packages in their repositories. You must uninstall these packages before you can install the official version of Docker Engine.

The unofficial packages to uninstall are:

  • docker.io
  • docker-compose
  • docker-doc
  • podman-docker

Moreover, Docker Engine depends on containerd and runc. Docker Engine bundles these dependencies as one bundle: containerd.io. If you have installed containerd or runc previously, uninstall them to avoid conflicts with the versions bundled with Docker Engine.

Older versions of Docker were called docker or docker-engine. Uninstall any such older versions:

$ for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

Images, containers, volumes, and networks stored in /var/lib/docker/ aren't automatically removed when you uninstall Docker. If you want to start with a clean installation, and prefer to clean up any existing data. To delete all images, containers, and volumes:

sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

Install Using APT Repository

Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker apt repository. Afterward, you can install and update Docker from the repository.

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get 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

# Add the repository to Apt sources:
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-get update

On some Debian-based Linux distributions, $(lsb_release -cs) may not return the Debian version codename, such as Kali Linux, BunsenLabs Linux.

Install Docker

Latest Docker

Update the apt package index and install the docker-ce package:

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Specific Version of Docker

# List the available versions:
apt-cache madison docker-ce | awk '{ print $3 }'

5:25.0.0-1~debian.12~bookworm
5:24.0.7-1~debian.12~bookworm
...

Select the desired version and install:

VERSION_STRING=5:25.0.0-1~debian.12~bookworm
sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin

Verify Docker

Verify that the installation is successful by running the hello-world image:

 sudo docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.

Install Using Convenience Script

For testing or development environments, Docker provides a convenience script to simplify the installation process on Debian systems. You can also use the --mirror option to install from a regional mirror:

If you want to install the test version of Docker, get the script from test.docker.com

# $ curl -fsSL test.docker.com -o get-docker.sh
$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror xxxx

After running this command, the script will automatically prepare everything and install the stable version of Docker on your system.

Start Docker

$ sudo systemctl enable docker
$ sudo systemctl start docker

Create Docker User Group

By default, the docker command uses a Unix socket to communicate with the Docker engine. Only the root user and users in the docker group can access the Docker engine's Unix socket. For security reasons, it's generally not recommended to use the root user on Linux systems. Therefore, a better practice is to add users who need to use docker to the docker user group.

Create the docker group:

$ sudo groupadd docker

Add the current user to the docker group:

$ sudo usermod -aG docker $USER

Log out and log back in for the changes to take effect. Then, test if Docker is installed correctly.

Test Docker Installation

$ docker run --rm hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
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.
(amd64)
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/

If you see the above output, it means the installation was successful.

Reference Documentation