Introduction
Docker Community Edition (CE) is the free version of Docker, which allows you to package applications and their dependencies into portable containers. Installing Docker CE on Linux unlocks capabilities for rapid development, testing, and deployment of software in an isolated environment. This guide will help you set up Docker on popular Linux distributions such as Ubuntu, Debian, CentOS, and Fedora using the official Docker repository.
After following these instructions, you will be able to run Docker containers, manage images and networks, and use tools like Docker Compose. The process takes about 10–15 minutes and requires basic knowledge of working with the terminal.
Prerequisites
Before starting the installation, ensure your system meets the following requirements:
- 64-bit Linux system: Docker CE supports x86_64, ARM, and other architectures, but this guide focuses on x86_64.
- Terminal access with superuser (sudo) or root privileges.
- Internet connection to download packages and the Docker repository.
- Supported distribution: Ubuntu 20.04+, Debian 10+, CentOS 7+, Fedora 30+. For the latest list of supported versions, see the official Docker documentation.
💡 Tip: If you use a less common distribution, check if it has a Docker package in its official repositories, but for the latest versions, the official Docker repository is recommended.
Step 1: Update System and Install Dependencies
Before adding the Docker repository, update the package list and install necessary utilities. Commands differ for Debian/Ubuntu-based distributions (apt) and CentOS/Fedora (yum/dnf).
For Ubuntu and Debian
Run the following commands in the terminal:
sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
apt updateupdates the package cache.apt-transport-httpsallows using HTTPS repositories.ca-certificatesprovides SSL certificate verification.curlis used to download the GPG key.software-properties-commonadds theadd-apt-repositorycommand (optional but useful).
For CentOS and Fedora
For CentOS 7/8 and Fedora, use yum or dnf:
sudo yum update -y
sudo yum install -y yum-utils device-mapper-persistent-data lvm2 curl
yum-utilsprovides theyum-config-managerutility.device-mapper-persistent-dataandlvm2are required for Docker storage.curlis for downloading the key.
⚠️ Important: On Fedora, you can use
dnfinstead ofyum, but the commands are compatible. Ensureyum-utilsis installed.
Step 2: Add the Official Docker Repository
Docker provides its own repository with up-to-date package versions. Add the Docker GPG key to verify package authenticity and configure the repository.
For Ubuntu and Debian
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- The first command downloads the Docker GPG key and saves it to
/usr/share/keyrings/docker-archive-keyring.gpg. - The second command adds the repository to
/etc/apt/sources.list.d/docker.list. Replaceubuntuwithdebianfor Debian. $(lsb_release -cs)automatically detects your distribution's codename (e.g.,jammyfor Ubuntu 22.04).
For CentOS and Fedora
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- This command adds the Docker repository for CentOS. For Fedora, the repository is similar, but sometimes
https://download.docker.com/linux/fedora/docker-ce.repois required. If errors occur, check the current URL in the Docker documentation.
💡 Tip: If the
yum-config-managercommand is unavailable, installyum-utils(see Step 1) or manually create a repository file at/etc/yum.repos.d/docker-ce.repo.
Step 3: Install Docker CE
After configuring the repository, install the Docker CE packages and additional components like Docker Compose (as a plugin) and BuildKit.
For Ubuntu and Debian
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
docker-ce— the core Docker engine.docker-ce-cli— thedockercommand-line client.containerd.io— container management.docker-buildx-plugin— build extension for creating images.docker-compose-plugin— plugin for Docker Compose (instead of a separate binary).
For CentOS and Fedora
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
The package names are the same. If you use dnf on Fedora, replace yum with dnf.
Step 4: Configure the Docker Service and User Permissions
By default, Docker requires superuser privileges. For convenience, configure the service to start automatically and add your user to the docker group.
# Start the Docker service
sudo systemctl start docker
# Enable autostart on system boot
sudo systemctl enable docker
# Add the current user to the docker group
sudo usermod -aG docker $USER
⚠️ Important: After adding a user to the
dockergroup, you must log out and log back in for the changes to take effect. Alternatively, runnewgrp dockerin the current terminal, but this will only work for that session.
Step 5: Verify the Installation
To confirm Docker is working correctly, run the hello-world test container:
docker run hello-world
If the installation was successful, you will see a welcome message confirming that Docker can pull images and run containers. Example output:
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
Potential Issues
Common errors that may occur when installing Docker CE on Linux include:
- Permission denied error: Ensure the user is added to the
dockergroup (see Step 4) and has re-logged in. Check group membership:groups $USER. - Docker service not running: Check service status:
sudo systemctl status docker. If inactive, start it:sudo systemctl start docker. - Repository addition error: Verify the GPG key was added correctly (
ls /usr/share/keyrings/docker-archive-keyring.gpg) and the repository URL matches your distribution. For Debian, replaceubuntuwithdebianin the repository addition command. - Package conflicts on Fedora: Fedora may have its own Docker package versions in repositories. If conflicts arise, disable the Fedora repository for Docker or use the official Docker repository with a specified version.
- Outdated dependencies: Older distributions may lack required packages. Update your system or consider using a newer distribution version.
If the issue persists, check Docker logs: sudo journalctl -u docker.service and search for solutions in the Docker community or official documentation.