Install Docker on Ubuntu 20.04

Docker is available within the ubuntu repositories, however if you prefer to run the last available stable version you can add the docker repositories directly to use as the source.

We will need to uninstall the existing version first though:

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

As you can see, we don't have it installed. So all good to continue. Next we need to update the package index and install packages to allow the use of HTTPs:

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

We now need to add the GPG key as follows:

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

Then we add the stable repository:

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

Next we need to ensure the public key is available:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Finally we can install docker:

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

Finally, we can test that docker is installed and working by running the docker image "hello world". This will download the image, and run it as demonstrated below:

jon@ubuntu-vps:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:bfea6278a0a267fad2634554f4f0c6f31981eea41c553fdf5a83e95a41d40c38
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

jon@ubuntu-vps:~$ 

Finally, delete the "hello world" container if you wish. To do this we can use the command below to find the Container ID.

sudo docker ps -a
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
3332391033f6   hello-world   "/hello"   5 minutes ago   Exited (0) 5 minutes ago             serene_jackson

Then we can simply delete the container.

sudo docker rm 3332391033f6

Thats All Folks.