Categories
Linux

How to install Docker on Ubuntu 20.04

It’s easy to install Docker on Ubuntu 20.04 and only needs 5 steps. In this tutorial, you will also learn how to add Docker key, set up Docker’s repository on Ubuntu 20.04.

Docker is an open framework to build, launch, and run applications. Installing Docker helps you to isolate your software from the underlying hardware, and you can deploy apps rapidly. After setting up Docker, you will manage your resources in the same manner as you are managing your apps. Using Docker’s approaches to ship, test, and release your software, you will greatly reduce the time between writing the application and running the application in production.

Instead of downloading and installing Docker through sudo apt install docker.io from the official Ubuntu 20.04 repository, here we prefer to install Docker from its own official repository download.docker.com as Ubuntu 20.04’s docker.io package might become outdated soon.

Prerequisite

To install Docker on Ubuntu 20.04, you’ll need to have access to the terminal, or you’ll need to be able to login to your Ubuntu 20.04 computer via ssh.

You should have root access to the user you used to log in to Ubuntu 20.04. This is required for Docker system-wide installation on Ubuntu 20.04.

Software needed to set up Docker key

First, we are going to install the software need for Docker installation on Ubuntu 20.04. They include apt-transport-https, ca-certificates, curl, gnupg-agent, and software-properties-common. You may have already installed them, so using apt update won’t change anything.

sudo apt update
sudo apt install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

After executing the above commands, you can see the following output to review for certain information of the Ubuntu 20.04 installation of Docker, such as what new programs must be installed and how much storage space it requires. Type “Y” and click enter, or press enter to proceed to download and install them.

Reading package lists… Done
Building dependency tree
Reading state information… Done
ca-certificates is already the newest version (20190110ubuntu1).
curl is already the newest version (7.68.0-1ubuntu2).
software-properties-common is already the newest version (0.98.9).
The following NEW packages will be installed:
apt-transport-https gnupg-agent
0 upgraded, 2 newly installed, 0 to remove and 31 not upgraded.
Need to get 6,940 B of archives.
After this operation, 206 kB of additional disk space will be used.
Do you want to continue? [Y/n]

Set up the official Docker key

Next, we’ll add the Docker key to stop a man-in-middle assault and make sure you download the actual file from docker.com.

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

If you see OK output, the Docker key has been successfully added.

Add docker key for Heimdall installation

Set up Docker’s Ubuntu repo

Now we are going to add the official Docker repository for Ubuntu 20.04. The following command will add deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable to the sources.list file for you: /etc/apt/sources.list.

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"

You will see output close to the one below. Note the line starting with “Get:8:.

Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:2 http://dl.google.com/linux/chrome/deb stable InRelease
Hit:3 http://archive.ubuntu.com/ubuntu focal InRelease
Get:4 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB]
Hit:5 http://packages.ros.org/ros/ubuntu focal InRelease
Hit:6 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:7 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Get:8 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages [11.0 kB]
Fetched 75.5 kB in 1s (108 kB/s)
Reading package lists… Done
ouput after adding Docker repo

Warning

As of 5/13/2020, do not use the instruction on the official Docker installation, because it won’t work for ubuntu 20.04 because it has not been tested and will result in the following error.

Add docker repository
Ign:1 http://dl.google.com/linux/chrome/deb stable InRelease
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [107 kB]
Hit:4 http://dl.google.com/linux/chrome/deb stable Release
Hit:5 https://download.docker.com/linux/ubuntu bionic InRelease
Get:6 http://archive.ubuntu.com/ubuntu focal-updates InRelease [107 kB]
Ign:8 https://download.docker.com/linux/ubuntu focal InRelease
Err:9 https://download.docker.com/linux/ubuntu focal Release
404 Not Found [IP: 13.35.82.24 443]
Get:10 http://archive.ubuntu.com/ubuntu focal-backports InRelease [98.3 kB]
Reading package lists… Done
E: The repository 'https://download.docker.com/linux/ubuntu focal Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

If you see some error like above, that is because as of the time of writing the focal (the codename of Ubuntu 20.04) branch is not available yet, we changed $(lsb_release -cs) to bionic earlier(the codename of Ubuntu 18.04).

Install Docker on Ubuntu 20.04

Next, we’ll need to get up-to-date information from the Docker Ubuntu repositories via apt update.

sudo apt update

You can see very similar output as follows:

get up-to-date information from the Docker Ubuntu repositories via apt update.
vh@varhowto-com:~$ sudo apt update
Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:2 https://download.docker.com/linux/ubuntu bionic InRelease
Ign:3 http://dl.google.com/linux/chrome/deb stable InRelease
Hit:4 http://dl.google.com/linux/chrome/deb stable Release
Hit:5 http://archive.ubuntu.com/ubuntu focal InRelease
Get:7 http://archive.ubuntu.com/ubuntu focal-updates InRelease [107 kB]
Get:8 http://archive.ubuntu.com/ubuntu focal-backports InRelease [98.3 kB]
Fetched 205 kB in 1s (243 kB/s)
Reading package lists… Done
Building dependency tree
Reading state information… Done
31 packages can be upgraded. Run 'apt list --upgradable' to see them.

Next we install Docker Engine Community version and the command line interface through sudo apt install docker-ce docker-ce-cli containerd.io.

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

You will see output like the following. Press enter to proceed.

image 43
vh@varhowto-com:~$ sudo apt install docker-ce docker-ce-cli containerd.io
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
aufs-tools cgroupfs-mount pigz
The following NEW packages will be installed:
aufs-tools cgroupfs-mount containerd.io docker-ce
docker-ce-cli pigz
0 upgraded, 6 newly installed, 0 to remove and 31 not upgraded.
Need to get 85.7 MB of archives.
After this operation, 385 MB of additional disk space will be used.
Do you want to continue? [Y/n]

It needs 385 MB space, which is kind of large…

Verify if Docker is installed on Ubuntu 20.04

After you install Docker, it will add docker.service to systemd and auto-start. To check whether the docker has been launched automatically, use sudo service docker status:

sudo service docker status

If you see green text “active (running)” in the output stream, this indicates that Docker has been successfully installed on your ubuntu 20.04 machine and running in the background:

docker status on Ubuntu 20.04
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2020-05-13 21:58:28 EDT; 17min ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 914 (dockerd)
Tasks: 24
Memory: 90.7M
CGroup: /system.slice/docker.service
├─ 914 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

We can also check the Docker version as well by running sudo docker -v. In my case it will output Docker version 19.03.8, build afacb8b7f0.

sudo docker -v
image 42

How to uninstall Docker on Ubuntu 20.04

In case you want to remove Docker from your Ubuntu 20.04 computer, you can use apt remove, which will remove the 3 Docker packages,docker-ce, docker-ce-cli, containerd.io, which we installed earlier.

sudo apt remove docker-ce docker-ce-cli containerd.io

You will see output like the following photo:

output while removing docking on Ubuntu 20.04
vh@varhowto-com:~$ sudo apt remove docker-ce docker-ce-cli containerd.io
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages were automatically installed and are no longer required:
aufs-tools cgroupfs-mount pigz
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
containerd.io docker-ce docker-ce-cli
0 upgraded, 0 newly installed, 3 to remove and 46 not upgraded.
After this operation, 384 MB disk space will be freed.
Do you want to continue? [Y/n]

Reference:

https://docs.docker.com/engine/install/

https://docs.docker.com/engine/install/ubuntu/

5 steps to install Docker on Ubuntu 20.04

Time Needed : 5 minutes

  1. Install Software needed to set up Docker key

    Run sudo apt update && install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

    image 15

  2. Set up the official Docker key

    Run curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    image 16

  3. Set up Docker’s Ubuntu repo

    Run sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"image 40

  4. Install Docker CE, CLI on Ubuntu 20.04

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

    image 43

  5. Verify if Docker is installed on Ubuntu 20.04

    Run sudo service docker status
    image 41

Tools
  • Terminal
  • SSH
Materials
  • Linux (Ubuntu 20.04)

+2

By VarHowto Editor

Welcome to VarHowto!