Skip to main content

Install Docker Engine on Linux

This lesson covers the production-ready installation of Docker Engine (Community Edition) on Linux. By the end, you will have the Docker daemon running, the CLI working, and a verified baseline.

Prerequisite

You need sudo access on the target host.

Quick Install Script (Development and Testing Only)

Docker provides a convenience script that detects your distribution and installs everything automatically. This is useful for lab environments, but do not use it in production without reviewing the script first.

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

For production servers, use the manual method below so you have full control over repository configuration and package versions.

Production Install on Ubuntu / Debian

Step 1: Remove Conflicting Packages

If you have older or unofficial Docker packages installed, remove them first. This prevents package conflicts.

for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do
sudo apt-get remove -y $pkg
done

Step 2: Add the Official Docker Repository

Docker packages in your distribution's default repository are often outdated. Adding Docker's official repository ensures you get the latest stable version.

# Install prerequisites for HTTPS repository access
sudo apt-get update
sudo apt-get install -y ca-certificates curl

# Add Docker's official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to your sources list
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
Debian Users

Replace ubuntu with debian in the repository URL above if you are running Debian instead of Ubuntu.

Step 3: Install Docker Packages

This installs the Docker daemon, CLI, containerd runtime, and the Compose and BuildX plugins.

sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Step 4: Verify the Installation

Run the hello-world test container to confirm everything works.

sudo docker run --rm hello-world

You should see a message starting with "Hello from Docker!" confirming that the daemon is running, the CLI can communicate with it, and images can be pulled from Docker Hub.

Production Install on RHEL / CentOS / AlmaLinux

Step 1: Add the Docker Repository

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Step 2: Install Docker Packages

sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Step 3: Start and Enable Docker

On RHEL-based systems, Docker does not start automatically after installation. You need to start it manually and enable it for boot.

sudo systemctl start docker
sudo systemctl enable docker

Step 4: Verify

sudo docker run --rm hello-world

Post-Install Verification Checklist

After installation, run these commands to confirm that all components are working:

# Check daemon and CLI versions
docker version

# Check daemon configuration and system info
docker info

# Confirm the Compose plugin is installed
docker compose version

# Check default networks exist
docker network ls

# Check storage driver and disk usage
docker system df

If any of these commands fail, refer to the troubleshooting table below.

Troubleshooting

SymptomLikely CauseFix
docker: command not foundCLI package not installed, or PATH not refreshedReinstall docker-ce-cli, then log out and back in
Cannot connect to the Docker daemonDaemon not running, or permission issueRun sudo systemctl start docker and check status
permission denied while trying to connectYour user is not in the docker groupSee Post-Install User and Permissions
Repository package conflicts during installLeftover unofficial packagesRe-run the conflict removal step, then reinstall
AppArmor or SELinux errorsKernel security module blocking DockerCheck dmesg and journalctl -u docker for details
Pull fails during verificationDNS or network egress blockedCheck /etc/resolv.conf and firewall rules

Reboot Validation

After installation, reboot the host once to confirm that Docker starts automatically at boot:

sudo reboot

After reconnecting:

systemctl status docker
docker ps
docker run --rm hello-world

If Docker does not start after reboot, you likely forgot to run systemctl enable docker. See the RHEL section above or the next lesson on post-install setup.

Key Takeaways

  • Always use Docker's official repository, not your distribution's default packages.
  • The convenience script (get.docker.com) is for testing only -- use manual installation for production.
  • Install all five packages: docker-ce, docker-ce-cli, containerd.io, docker-buildx-plugin, docker-compose-plugin.
  • Verify the installation immediately with docker run --rm hello-world.
  • Reboot once and confirm Docker starts automatically.

What's Next