Tutorial

2026 Debian 13 Tutorial: Installing Docker and Docker Compose

2026-06-30 #Docker#Docker Compose#Debian#Linux

Nowadays, more and more applications can be deployed with one click using Docker. This article will introduce how to install Docker and Docker Compose on the latest Debian 13 (Trixie).

Verify environment

1
2
3
4
5
6
root@debian:~# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 13 (trixie)
Release: 13
Codename: trixie

This installation is equally applicable to Ubuntu 26.04.

Introduction to Docker

Docker is an open-source containerization platform that can package an application and its dependencies into a lightweight, portable container, allowing it to run consistently in any environment.

  • Lightweight: Containers share the host machine's OS kernel, enabling fast startup times and low resource footprint.
  • Portable: Containers can run consistently across development, testing, and production environments, solving the "inconsistent environments" problem.
  • Isolation: Each container runs independently without affecting others.
  • Rapid Deployment: Achieves fast packaging, publishing, and deployment of applications through image technology.

Introduction to Docker Compose

Docker Compose is a tool provided by Docker for defining and managing multi-container applications. Through a simple YAML file docker-compose.yml, you can define and start multiple service containers, making the deployment and management of applications much more convenient without needing to use long docker run commands.

Features:

  • Multi-container Management: Start, stop, and manage multiple containers simultaneously.
  • Configuration via YAML: Define services, networks, storage, etc., via docker-compose.yml.
  • Simplified Commands: Manage containers using the single command docker compose.

This article will cover installing the V2 version, which corresponds to the docker compose command.

Installing from the Official Repository

The following operations must be completed as the root user. Please use sudo -i or su root to switch to the root user for operation.

First, install some essential packages:

1
2
3
apt update
apt upgrade -y
apt install curl vim wget gnupg dpkg apt-transport-https lsb-release ca-certificates

Then add Docker's GPG public key and apt repository:

1
2
curl -sSL https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://download.docker.com/linux/debian $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list

For machines located in mainland China, you can use the domestic mirror from Tsinghua TUNA:

1
2
curl -sS https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list

After updating the system, you can then install Docker CE and the Docker Compose plugin:

1
2
apt update
apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin

At this point, you can use the docker version command to check if the installation was successful:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Client: Docker Engine - Community
Version: 29.6.1
API version: 1.55
Go version: go1.26.4
Git commit: 8900f1d
Built: Fri Jun 26 11:40:34 2026
OS/Arch: linux/amd64
Context: default

Server: Docker Engine - Community
Engine:
Version: 29.6.1
API version: 1.55 (minimum version 1.40)
Go version: go1.26.4
Git commit: 8ec5ab3
Built: Fri Jun 26 11:40:34 2026
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v2.2.5
GitCommit: e53c7c1516c3b2bff98eb76f1f4117477e6f4e66
runc:
Version: 1.3.6
GitCommit: v1.3.6-0-g491b69ba
docker-init:
Version: 0.19.0
GitCommit: de40ad0

If you need to run Docker in non-root mode, you can add specific users to the docker group. For example, let's add the www-data user:

1
2
apt install docker-ce-rootless-extras
sudo usermod -aG docker www-data

Docker Compose V2

Docker now comes with the Docker Compose V2 version out-of-the-box, which is the docker compose command:

1
2
root@debian:~# docker compose version 
Docker Compose version v5.2.0

Modify Docker Configuration

The following configuration will add a custom internal IPv6 subnet, enable IPv6 functionality for containers, and limit log file sizes to prevent Docker logs from filling up the hard drive:

1
2
3
4
5
6
7
8
9
10
11
12
13
cat > /etc/docker/daemon.json << EOF
{
"log-driver": "json-file",
"log-opts": {
"max-size": "20m",
"max-file": "3"
},
"ipv6": true,
"fixed-cidr-v6": "fd00:dead:beef:c0::/80",
"experimental":true,
"ip6tables":true
}
EOF

Then restart the Docker service:

1
systemctl restart docker

Guide to Common Docker Commands

Here is a quick overview of common docker commands, though using docker compose for management will be much more convenient.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Pull an image
docker pull <image_name>:<tag>

# View currently running containers
docker ps

# View all containers (including stopped ones)
docker ps -a

# View local images
docker images

# Delete an image
docker rmi <image_id_or_name>
docker rmi ubuntu:latest

# Run a container
docker run -d -p <host_port>:<container_port> --name <container_name> <image_name>

# Start, stop, restart, remove
docker start / stop / restart / rm <container_name_or_id>

# Enter a container to execute interactive commands
docker exec -it <container_name_or_id> /bin/bash

# View container logs
docker logs <container_name_or_id>

# Query disk space used by Docker:
docker system df

# Remove all unused images
docker image prune -a

Guide to Using Docker Compose

docker compose needs to be executed in the working directory where the docker-compose.yml file is located. It is highly recommended to create a dedicated working directory to centrally store configuration files, for example:

1
2
3
4
5
6
7
docker/
├── nginx/
│ └── docker-compose.yml
├── mysql/
│ └── docker-compose.yml
└── redis/
└── docker-compose.yml

Common docker compose commands:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Pull and update images
docker compose pull

# Start containers
docker compose up

# Start containers in the background
docker compose up -d

# Stop containers
docker compose stop

# Stop containers and remove created networks, volumes, and images
docker compose down

# Restart containers
docker compose restart

# View running services
docker compose ps

# View logs
docker compose logs
# View logs in real-time
docker compose logs -f

# Enter a container to execute interactive commands
docker compose exec <service_name> <command>
docker compose exec nginx /bin/bash

# View service statistics, displaying real-time CPU, memory, and other resource usage.
docker compose stats

Still find docker compose too long to type? Execute the commands below, and you'll be able to use dc as an alternative:

Before executing, run dc once to confirm the command is not currently in use. After execution, run dc version to verify.

1
2
echo 'alias dc="docker compose"' >> ~/.bashrc 
source ~/.bashrc

Effect:

1
2
3
4
5
root@debian:~# dc
-bash: dc: command not found

root@debian:~# dc version
Docker Compose version v5.2.0

Afterward, whenever we create a docker-compose.yml file, starting or updating the service only requires executing:

1
2
dc pull
dc up -d

Now head over to GitHub or Docker Hub to find some interesting projects!

Comments
Share

Comments