How to Install Docker On Ubuntu 20.04 LTS Focal Fossa

In this tutorial, we are going to be looking at Docker setup, by far one of the most popular container solutions out there. While Docker is available on Windows, Mac, and various Linux distributions, we’ll be working off an Ubuntu 20.04 server.

$ lsb_release -a
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal

Spin up and SSH into the server. When working with Linux, Docker follows the same basic steps when installing Docker regardless of distributions. First, we configure the Docker repository, and then finally we install the needed Docker packages themselves.

Prerequisites

Let’s start with updating our machine.

$ sudo apt update

And then install any prerequisite packages.

$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

We can now add Docker’s GPG key.

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK

And verify its configuration.

$ sudo apt-key fingerprint 0EBFCD88
pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

To add the Docker repository, we now just need to run:

$ sudo add-apt-repository  "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Hit:1 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-backports InRelease
Get:4 https://download.docker.com/linux/ubuntu focal InRelease [36.2 kB]
Hit:5 http://security.ubuntu.com/ubuntu focal-security InRelease
Get:6 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [3056 B]
Fetched 39.2 kB in 0s (83.8 kB/s)
Reading package lists... Done

And update our server again.

$ sudo apt update

Make sure you are about to install from the Docker repo instead of the default Ubuntu repo:

$ apt-cache policy docker-ce
docker-ce:
  Installed: (none)
  Candidate: 5:19.03.12~3-0~ubuntu-focal
  Version table:
     5:19.03.12~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.11~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.10~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.9~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages

Installing Docker

We can now install the necessary packages.

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

$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-09-05 22:53:29 UTC; 1min 22s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 3945 (dockerd)
      Tasks: 8
     Memory: 45.5M
     CGroup: /system.slice/docker.service
             └─3945 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Executing the Docker Command Without Sudo (Optional)

To finish up, we want to add our ubuntu user to the docker group.

$ sudo usermod -aG docker ${USER}

$ id -nG
ubuntu adm dialout cdrom floppy sudo audio dip video plugdev netdev lxd docker

You can also confirm the change using the grep command as follows.

$ grep docker /etc/group
docker:x:998:ubuntu

Working with Docker Images

Log out then log back in to refresh the Bash session before running any docker commands.

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:7f0a9f93b4aa3022c3a4c147a449bf11e0941a1fd0bf4a8e6c9408b2600777c5
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/

Now check the images status on server.

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              bf756fb1ae65        8 months ago        13.3kB

To install Ubuntu image we will first search with the following command.

$ docker search ubuntu
NAME                                                      DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
ubuntu                                                    Ubuntu is a Debian-based Linux operating sys…   11285               [OK]       
dorowu/ubuntu-desktop-lxde-vnc                            Docker image to provide HTML5 VNC interface …   459                                     [OK]
rastasheep/ubuntu-sshd                                    Dockerized SSH service, built on top of offi…   246                                     [OK]
consol/ubuntu-xfce-vnc                                    Ubuntu container with "headless" VNC session…   225                                     [OK]
ubuntu-upstart                                            Upstart is an event-based replacement for th…   110                 [OK]       
ansible/ubuntu14.04-ansible                               Ubuntu 14.04 LTS with ansible                   98                                      [OK]
neurodebian                                               NeuroDebian provides neuroscience research s…   69                  [OK]       
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5      ubuntu-16-nginx-php-phpmyadmin-mysql-5          50

You need to execute the below mentioned command to download the official ubuntu image which is indicated with OK in OFFICIAL column:

$ docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
54ee1f796a1e: Pull complete
f7bfea53ad12: Pull complete
46d371e02073: Pull complete
b66c17bbf772: Pull complete
Digest: sha256:31dfb10d52ce76c5ca0aa19d10b3e6424b830729e32a89a7c6eee2cda2be67a5
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest

You can now see the ubuntu latest image as follows.

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              4e2eef94cd6b        2 weeks ago         73.9MB
hello-world         latest              bf756fb1ae65        8 months ago        13.3kB

Conclusion

That’s all you need to know about installation of Docker on Ubuntu 20.04 server. There are more tutorials that will go into deeper explanation of using Docker thoroughly, but this is a simple article to just get familiar with installation on linux based server.

Avatar photo

Asif Khan

Responsible and proactive professional with more than 13 years of experience in IT systems, open source software applications, DevOps, Linux systems, and cloud operations. My main goals are to automate things, keep them safe, and make sure they are strong. I am very good at planning and building the infrastructure for services that people really want. I was drawn to the fast-paced world of cloud computing because it has resources that can be scaled up or down as needed. One of my best skills is being able to use a lot of different DevOps tools to set up, release management, and microservices ecosystems, as well as for provisioning, orchestration, and configuration management.