How to Setup Docker Engine on Linux

Written by:

Categories:

This guide will follow the offical documentation from docs.docker.com, covering both Debian and Fedora based distributions. At the time of writing Debian Bookworm 12 and Fedora 39 are the latest versions supported by Docker. Skip to the Fedora section here.

Debain

Begin by uninstalling old and conflicting packages with Docker:

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

We will install with the apt repository method as it’s fairly simple and will ensure automatic updates through your package manager:

sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

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

Now to install the latest version of Docker Engine, run:

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

Congrats! Docker is installed and ready to use. But every command will have to be prefixed with sudo to work. Let’s fix that:

sudo usermod -aG docker $USER && newgrp docker

We can now test our install with:

docker run hello-world

Now docker will run without sudo and automatically update with our package manager!

Fedora

Begin by uninstalling old and conflicting packages with Docker:

sudo dnf remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

We will install with the dnf repository method as it’s fairly simple and will ensure automatic updates through your package manager:

sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo

Now to install the latest version of Docker Engine, run:

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

Now start the Docker service to have docker auto start on boot:

sudo systemctl enable docker && sudo systemctl start docker

Congrats! Docker is installed and ready to use. But every command will have to be prefixed with sudo to work. Let’s fix that:

sudo usermod -aG docker $USER && newgrp docker

We can now test our install with:

docker run hello-world

Now docker will run without sudo and automatically update with our package manager!

Latest Articles