How to Run Docker Containers on Debian 12 Bookworm System
Categories:
5 minute read
With the release of Debian 12 “Bookworm”, system administrators and developers are taking advantage of the stability and improvements that come with the new version. Docker, a powerful platform for developing, shipping, and running applications inside lightweight containers, remains one of the most commonly used tools in the DevOps toolkit. Whether you’re running a production-grade server or just want to experiment with containerized applications, Docker on Debian 12 is a solid combination.
This guide walks you through installing Docker on Debian 12 Bookworm, configuring it properly, and running your first container. Whether you’re a beginner or someone with moderate Linux experience, this step-by-step article will help you get started confidently.
What is Docker?
Docker is an open-source platform that allows developers to package applications and their dependencies into containers. These containers are lightweight, portable, and consistent across different environments, making development, testing, and deployment processes much more efficient.
Some key benefits of Docker include:
- Isolation: Each container is isolated from the host and other containers.
- Reproducibility: Developers can ship the same container across development, testing, and production environments.
- Portability: Containers can run anywhere Docker is installed—on local machines, virtual machines, cloud providers, etc.
- Efficiency: Docker containers are lightweight and start faster compared to traditional virtual machines.
Step 1: Update Your System
Before installing Docker, it’s best practice to update your system packages to the latest versions.
sudo apt update
sudo apt upgrade -y
Make sure curl
, ca-certificates
, and gnupg
are installed, as you’ll need these tools for setting up Docker’s repository.
sudo apt install ca-certificates curl gnupg lsb-release -y
Step 2: Add Docker’s Official Repository
Docker is not included by default in Debian’s official repositories, especially not the latest stable version. You’ll need to add Docker’s official repository.
1. Add Docker’s GPG Key
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
2. Add Docker Repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
3. Update Your Package Index
sudo apt update
Now that the Docker repository is configured, you’re ready to install Docker.
Step 3: Install Docker Engine
Install Docker Engine, CLI, and the Containerd runtime:
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
To verify Docker is installed correctly:
docker --version
Expected output (version may vary):
Docker version 24.0.5, build ced0996
Step 4: Start and Enable Docker
Docker should start automatically after installation. You can check its status with:
sudo systemctl status docker
To ensure Docker starts at boot time:
sudo systemctl enable docker
If Docker isn’t running, start it manually:
sudo systemctl start docker
Step 5: Run Docker Without sudo
By default, Docker commands need to be run with sudo
. To allow a non-root user to run Docker commands:
sudo usermod -aG docker $USER
After this, log out and back in or reboot the system to apply group changes. You can test if it works:
docker info
If it runs without error, the setup is successful.
Step 6: Test Docker by Running a Container
Now that Docker is running, you can test it with the popular hello-world
image.
docker run hello-world
Docker will pull the image from Docker Hub and run it. You should see a confirmation message that Docker is working correctly.
Step 7: Basic Docker Commands
Here are a few essential Docker commands to get you started:
Pull an Image
docker pull nginx
Run a Container
docker run -d -p 8080:80 --name webserver nginx
-d
: Detached mode (runs in background)-p
: Maps host port 8080 to container port 80--name
: Assigns a name to the container
Visit http://localhost:8080
in your browser. You should see the Nginx welcome page.
List Running Containers
docker ps
Stop a Container
docker stop webserver
Remove a Container
docker rm webserver
Remove an Image
docker rmi nginx
Step 8: Using Docker Compose (Optional)
Docker Compose is a tool for defining and running multi-container Docker applications using YAML files.
Check if it’s installed
docker compose version
If you installed Docker with the docker-compose-plugin
, it should work out of the box.
Example: Running a WordPress Stack
Create a file named docker-compose.yml
:
version: '3.1'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: rootpass
wordpress:
image: wordpress:latest
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: user
WORDPRESS_DB_PASSWORD: password
WORDPRESS_DB_NAME: wordpress
Run it:
docker compose up -d
Visit http://localhost:8080
to complete the WordPress setup.
Step 9: Managing Docker on Debian 12
Here are some tips for managing Docker effectively on Debian 12 Bookworm:
Clean Up Unused Resources
docker system prune -a
This removes all stopped containers, unused networks, and dangling images.
View Docker Logs
docker logs <container_name_or_id>
Monitor Docker Resources
docker stats
Shows real-time usage statistics for containers.
Security Tips for Production
- Use firewall rules to restrict access to Docker-exposed ports.
- Disable root inside containers when possible.
- Scan images for vulnerabilities using tools like
docker scan
orTrivy
. - Keep Docker and the host OS updated regularly.
- Use Docker secrets for managing sensitive data (available in Docker Swarm mode).
Conclusion
Running Docker containers on Debian 12 Bookworm is a straightforward process that unlocks a world of possibilities for software development, testing, and deployment. With the stability and long-term support of Debian and the flexibility of Docker, you have a powerful combination at your fingertips.
By following the steps in this guide, you should now have Docker installed and be able to run and manage containers efficiently. Whether you’re deploying a simple web server or a complex multi-container application, Docker offers the tools and ecosystem to do it reliably.
Keep exploring, experiment safely in containers, and consider digging into more advanced Docker topics like Docker Swarm, Kubernetes, volume management, and custom image building.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.