Docker has become an essential tool for developers, DevOps engineers, and system administrators. It allows you to run applications in lightweight, isolated containers, making deployment faster, more consistent, and easier to manage.

In this tutorial, we will walk through step-by-step guide on how to install Docker and Docker Compose on Debian from scratch so even newbie can understand.
We will cover:
- What is Docker & Docker Compose.
- Prerequisites.
- Step-by-step installation of Docker on Debian.
- Step-by-step installation of Docker Compose.
- Post-installation configuration.
- Testing your Docker setup.
- Troubleshooting Common Errors.
1. Understanding Docker and Docker Compose.
Docker is a platform that allows you to create, deploy, and run applications inside containers. These containers are portable and ensure the application runs the same way regardless of the environment.
Docker Compose is a tool that lets you define and run multi-container Docker applications using a single YAML file. It’s extremely useful for deploying complex stacks (e.g., web server + database + cache) with a single command.
2. Prerequisites.
Before installing Docker, make sure you have:
- A system running Debian 11 (Bullseye), Debian 12 (Bookworm), or newer
- A sudo user or root access
- An active internet connection
3. Step-by-Step Installation of Docker on Debian.
Step 3.1: Update Your System.
Keeping your system up to date ensures that all packages and dependencies are the latest version.
sudo apt update && sudo apt upgrade -y
Step 3.2: Uninstall Old Docker Versions (if any).
If you have older Docker packages installed, remove them to avoid conflicts.
sudo apt remove docker docker-engine docker.io containerd runc
Step 3.3: Install Required Dependencies
Docker needs certain packages to be installed for secure repository management.
sudo apt install ca-certificates curl gnupg lsb-release -y
Step 3.4: Add Docker’s Official GPG Key.
We need to add Docker’s official GPG key to verify package authenticity.
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Step 3.5: Set Up the Docker Repository.
Now, add Docker’s official repository to your sources list.
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
Step 3.6: Install Docker Engine.
Update the package list and install Docker.
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
4. Step-by-Step Installation of Docker Compose.
Docker Compose is now available as a plugin in recent Docker versions, but you can also install it manually.
Method 1: Install as a Docker Plugin (Recommended).
If you installed the docker-compose-plugin
in Step 3.6, you can check it with:
docker compose version
Notice: The new syntax is
docker compose
(space) instead ofdocker-compose
(dash).
Method 2: Install Docker Compose Manually (Latest Release).
If you prefer the standalone binary:
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose
Make it executable:
sudo chmod +x /usr/local/bin/docker-compose
Verify installation:
docker-compose --version
5. Post-Installation Steps.
Step 5.1: Enable Docker to Start on Boot.
sudo systemctl enable docker
Step 5.2: Run Docker Without Sudo (Optional).
By default, Docker commands require sudo
. To allow your user to run Docker without sudo
:
sudo usermod -aG docker $USER
Log out and back in for the changes to take effect.
6. Testing Your Docker Setup.
Test Docker.
docker run hello-world
You should see a message confirming that Docker is working.
Test Docker Compose.
Create a docker-compose.yml
file:
version: '3'
services:
web:
image: nginx
ports:
- "8080:80"
Run:
docker compose up -d
Open your browser and visit:
http://localhost:8080
You should see the Nginx welcome page.
7. Troubleshooting Common Errors.
- Permission Denied → Add your user to the
docker
group. - Repository Not Found → Check that you added the correct Docker repo for your Debian version.
- Old Version Running → Remove old Docker packages before installing the new version.
Conclusion
You have successfully installed Docker and Docker Compose on Debian. Now you can start building and deploying containerized applications easily. Docker’s container-based architecture ensures your applications run consistently across different environments.
If you want to explore more, try deploying multi-container stacks using Docker Compose or setting up private Docker registries.
Leave a Reply