Why Install Docker from the Official Repository?
For developers and system administrators building modern applications, Docker is often the foundational layer. While Debian provides its own `docker.io` package, it frequently lags behind the latest releases. Installing Docker Engine and the Compose plugin directly from the official Docker repository offers two significant advantages: access to more current versions with faster security patches, and the official `docker compose` command, which is essential for many contemporary Compose recipes. This guide details the process for Debian 13 (Trixie), ensuring you have a robust and up-to-date Docker environment.
Prerequisites
Before you begin, ensure you have the following:
- A server running Debian 13 (Trixie).
- A user account with
sudoprivileges. For optimal security, it's recommended to have a hardened SSH setup.
Step 1: Remove Old Docker Versions
If you have previously installed Docker from Debian's default repositories, it's crucial to remove those packages to avoid conflicts. Run the following commands to uninstall any existing Docker installations:
sudo apt-get remove docker docker-engine docker.io containerd runc
This command targets the common package names. If you encounter errors indicating that some packages are not installed, you can safely ignore them. After removal, clean up any lingering configuration files or dangling images:
sudo apt-get autoremove --purge
Step 2: Set Up the Docker Repository
To install Docker from the official repository, you first need to add the repository to your system's sources list. This involves installing necessary tools, downloading Docker's GPG key, and configuring the repository.
Install Required Packages
First, update your package list and install packages that allow apt to use a repository over HTTPS:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
Add Docker's Official GPG Key
Next, create the directory for Docker's GPG key if it doesn't exist, and then download and add the key. This key verifies the authenticity of the Docker packages.
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
Configure the Docker Repository
Now, set up the Docker APT repository. This command adds the official Docker repository for Debian to your system's sources. Replace $(. /etc/os-release; echo "$VERSION_CODENAME") with your Debian version's codename if it differs (e.g., `bookworm` for Debian 12). For Debian 13, this correctly resolves to `trixie`.
echo
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian
$(. /etc/os-release; echo "$VERSION_CODENAME") stable" |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Update Package Index Again
After adding the new repository, update your package list to include packages from the Docker repository:
sudo apt-get update

Step 3: Install Docker Engine and Compose Plugin
With the repository configured, you can now install Docker Engine and the Compose plugin. The `docker-ce` package installs the Docker Engine, and `docker-compose-plugin` installs the official Compose functionality.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
This command installs the latest stable version of Docker Engine, its command-line interface (CLI), the Containerd runtime, and the Docker Compose plugin. If you need a specific version, you can list available versions using apt-cache madison docker-ce and then install it using sudo apt-get install docker-ce=.
Step 4: Verify the Installation
To confirm that Docker is installed and running correctly, run the hello-world container. This small image tests your Docker installation by printing an informational message and exiting.
sudo docker run hello-world
You should see output similar to this:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
... (downloading image)
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
Additionally, verify the Docker Compose installation:
docker compose version
This should output the installed version of Docker Compose, confirming it's available.
Step 5: Manage Docker as a Non-Root User
By default, running Docker commands requires sudo. To manage Docker without sudo, add your user to the docker group. Note that this grants the user privileges equivalent to the root user, so be mindful of the security implications.
sudo groupadd docker
sudo usermod -aG docker $USER
You need to log out and log back in for this change to take effect. After logging back in, you can run Docker commands without sudo:
docker run hello-world
This step significantly streamlines the development workflow. If you encounter issues, ensure you have logged out and back in completely, or try restarting your session.
Conclusion
You have now successfully installed Docker Engine and the Compose plugin on Debian 13 directly from the official Docker repository. This setup provides you with the latest features and security updates, ensuring your containerization environment is current and robust. This mirrors the approach taken in many advanced tutorials, such as those found on Serverküche, ensuring compatibility and access to the most up-to-date tooling.
