This post is a quick guide to installing docker on Ubuntu.

This guide assumes that you're working on a "blank" system, as in you've installed and updated Ubuntu but not been using it in anger.

The first step is to ensure that any incompatible versions of docker are removed from the system.

sudo apt remove docker docker-engine docker.io containerd runc

Ensure that some required software is installed (chances are these are already installed but let's make sure)

sudo apt update
sudo apt install ca-certificates curl gnupg lsb-release

Configure the docker repository to get the lastest stable version.

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

Install the docker engine. On Ubuntu, the installation defaults to starting the daemon and enabling it at boot.

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

Test docker is running

sudo docker run hello-world

This guide is also valid for the majority of Ubuntu based distros but there may be some changes you need to make. For example, Mint doesn't use the same code name as the Ubuntu distributions it's based on.

Note for installing docker on Mint Linux

Mint Linux is based on Ubuntu and uses the same docker repository, however we need to change the command that updates the sources.list file before the actual installation of the docker runtime.

The last step in preparing the environment before installing the docker runtime needs to be changed as follows.

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  focal stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

This is effectively the same command as for Ubuntu, but instead of using the variable $(lsb_release -cs) we specify focal

If not changed, the sources.list file would contain uma instead of focal and any installs would fail as the repository labeled uma does not exist.