Installing Docker and Docker Compose on Linux: Complete Guide
Docker & Containers · By Kevin Marcondes · Published on · Updated on · 9 min read
This guide walks you step by step through installing Docker and Docker Compose on Linux, covering Ubuntu/Debian, Fedora/CentOS, Arch, and openSUSE. You’ll set up repositories, install the Engine and Compose, enable the service, and test with an example container. At the end there are checks and common troubleshooting tips. Let’s get started.
Prerequisites and what you will install
You need an up-to-date Linux system, administrator access (sudo or root), and an internet connection. Docker relies on kernel features (namespaces and cgroups) and works well on modern distributions. Installing Compose lets you orchestrate services using a YAML file. Where appropriate we use the official Docker repositories; in other cases we rely on distribution packages.
If you are evaluating adoption, see the comparison between Docker and virtual machines to understand the trade-offs in availability and other aspects.
- An account with sudo or root privileges.
- Ports and DNS working to download packages and images.
- Disk space for images and volumes (default path is /var/lib/docker).
- systemd active to manage the Docker service.
| Distribution | Package manager | systemd service |
|---|---|---|
| Ubuntu/Debian | apt | docker |
| Fedora/CentOS/RHEL | dnf or yum | docker |
| Arch Linux | pacman | docker |
| openSUSE | zypper | docker |
Step 1 — Remove old versions (if any)
Before installing, remove old packages to avoid conflicts. This does not remove images and volumes by default. If you delete /var/lib/docker manually, you will lose images, volumes, and layers — back up any data you need to keep. This step is safe on systems where Docker is not yet in use.
# Ubuntu/Debian
sudo apt-get remove -y docker docker-engine docker.io containerd runc
# Fedora/CentOS/RHEL
sudo dnf remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine \
|| sudo yum remove -y docker docker-client docker-common docker-engine
# Arch Linux
sudo pacman -Rns --noconfirm docker docker-compose containerd runc
# openSUSE
sudo zypper remove -y docker docker-compose containerd runc
Step 2 — Add repository (when applicable) and prepare dependencies
On Debian/Ubuntu, use Docker’s official repository for up-to-date packages. On Fedora/CentOS/RHEL, add the corresponding repo. For Arch and openSUSE, the distribution packages are usually sufficient — refreshing the package index is enough. This step also installs utilities to download and validate GPG keys.
# Ubuntu (repositório Docker)
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Debian (repositório Docker)
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
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
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
# Fedora (repositório Docker)
sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
# CentOS/RHEL (repositório Docker)
sudo yum -y install yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# Arch Linux (índices da distribuição)
sudo pacman -Sy --noconfirm
# openSUSE (índices da distribuição)
sudo zypper refresh
Step 3 — Install the Docker Engine and CLI
Now install the Docker daemon, the CLI, and, when applicable, containerd. Package names vary slightly across distributions. After installation, the docker binary will be on your PATH and the service can be managed via systemd.
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
# Fedora/CentOS/RHEL
sudo dnf install -y docker-ce docker-ce-cli containerd.io \
|| sudo yum install -y docker-ce docker-ce-cli containerd.io
# Arch Linux
sudo pacman -S --noconfirm docker containerd
# openSUSE
sudo zypper install -y docker
Step 4 — Start, enable, and test the Docker service
Enable the service to start automatically at boot and run a simple test using the example image. The test pulls a small image, runs it, and prints a success message. If the service starts without errors, you can build images and run containers in CI/CD pipelines, for example using GitHub Actions.
sudo systemctl enable --now docker
sudo docker run --rm hello-world
sudo docker info
Step 5 — Run Docker without sudo (docker group)
For daily use, add your user to the docker group. This avoids needing sudo for every command. Warning: members of the docker group can gain privileges equivalent to root because the daemon has broad system access. Do this only for trusted users. After adding, open a new session to apply the group membership.
sudo groupadd -f docker
sudo usermod -aG docker "$USER"
# Aplique o grupo na sessão atual ou faça logoff/login
newgrp docker
# Teste sem sudo
docker run --rm hello-world
Step 6 — Install Docker Compose (v2 as a plugin; v1 where applicable)
Compose v2 integrates with Docker as a plugin. On distributions using Docker’s official repo, install the docker-compose-plugin package. On others, the docker-compose package may provide the classic v1 binary, which still works. Both allow you to define services in a YAML file and bring them up with a single command.
# Ubuntu/Debian (repositório Docker)
sudo apt-get update
sudo apt-get install -y docker-compose-plugin
# Verifique o plugin v2
docker compose version
# Fedora/CentOS/RHEL (repositório Docker)
sudo dnf install -y docker-compose-plugin || sudo yum install -y docker-compose-plugin
# Verifique o plugin v2
docker compose version
# Arch Linux (pacote da distribuição)
sudo pacman -S --noconfirm docker-compose
# Verifique a versão instalada (v1)
docker-compose --version
# openSUSE (pacote da distribuição)
sudo zypper install -y docker-compose
# Verifique a versão instalada (geralmente v1)
docker-compose --version
Final checks and common troubleshooting
Confirm everything is working: the service should be active, your user should be in the right group, and container networking should be reachable. Below are useful diagnostics. See also the structured logs and correlation guide for production logging.
Common errors and fixes:
• Permission denied on the socket: check that your user is in the docker group and restart the session.
• Failure to start: check the service logs and ensure the kernel supports cgroups/overlay2.
• No network in the container: verify DNS, internet access, and firewall/NAT rules.
• Corporate proxy: configure environment variables and, if needed, Docker’s systemd proxy settings.
- Permission denied on the socket: ensure docker group is active in your session.
- Daemon failing: check service logs and kernel modules.
- No network: review DNS, NAT, and firewall.
- Proxy environments: export HTTP(S)_PROXY and NO_PROXY variables per policy.
# Verificar status e logs
systemctl status docker --no-pager
journalctl -u docker -b --no-pager | tail -n 100
# Testar rede do container (DNS e IP)
docker run --rm alpine sh -c "ip addr; nslookup google.com || true"
# Conferir versões
docker version
docker compose version || docker-compose --version
Frequently asked questions
What’s the difference between Docker Compose v1 and v2?
Compose v2 is distributed as a Docker plugin and is invoked with the subcommand docker compose; v1 is a separate binary usually named docker-compose. Both let you define services in a YAML file and bring them up, but v2 is integrated with the Docker CLI and receives new features first in most distributions where the plugin is available.
Do I need hardware virtualization to use Docker?
No. Docker containers rely on Linux kernel isolation mechanisms such as namespaces and cgroups rather than hardware virtualization or a hypervisor. Typical container workloads run without virtualization. Some advanced workflows like certain emulation or multi-architecture build setups may use virtualization tools, but those are not required to run standard containers.
Where does Docker store images and volumes by default?
By default Docker stores container data, images and layers under /var/lib/docker. You can change the storage path by editing the daemon configuration and pointing Docker to another directory or disk. Moving or deleting that directory without proper backup can destroy images, volumes and other runtime data, so back up anything you need before changing it.
How do I completely uninstall Docker and remove data?
Uninstall Docker packages with your distribution’s package manager to remove the engine and CLI. To remove all runtime data, delete /var/lib/docker and /var/lib/containerd manually; this will erase images, volumes and layers. The guide warns to back up any important data before deleting these directories because the deletion is irreversible for stored container data.
Is it safe to add my user to the docker group?
Adding your user to the docker group removes the need for sudo but grants privileges equivalent to root because the Docker daemon can control system resources. It’s commonly done on personal workstations, but on multiuser or production servers prefer controlled sudo rules or access policies. If you add the user, open a new session to apply the group membership.
Want to go further with containers?
If you’d like to discuss advanced scenarios (deployments, CI/CD, security, and logging) or have your configuration reviewed, send a message and we’ll talk.
Talk about containersSee also
- Tutorial: Implement Canary releases with Traefik in Docker Compose using headers and weighted routing for gradual PHP deployments
- Tutorial: Configure HAProxy with Let's Encrypt and health checks to load balance traffic between Docker containers on a VPS (step-by-step)
- Hands‑On Tutorial: Implement mTLS Between Nginx and Microservices with smallstep CA in Docker Compose
- Tutorial: configure cgroup v2 and systemd ResourceControl to limit CPU, memory and I/O for Docker containers on Debian