How to install and configure Docker-CE on Ubuntu 20.04

In this tutorial am going to show you how you can install Docker-CE on Ubuntu 20.04.

Docker is a set of platform as a service product that uses OS-level virtualization to deliver software in packages called containers. Containers are usually isolated from one another and bundled their own software libraries and configuration files, they can communicate with each other through well-defined channels.

Docker makes it possible to get more apps running on the same old servers and also makes it easy to package and ship programs.

Related Articles

Prerequisites

  • Make sure you have user with sudo privileges
  • Have Ubuntu 20.04 server up and running
  • Have basic kwoledge about running commands on a terminal

Table of Contents

  1. Run system updates
  2. Uninstall old docker version
  3. Install Docker Engine
  4. Enable Docker Engine
  5. Start Docker
  6. Check Docker status
  7. Test Docker
  8. Conclusion

1. Run system updates

We need to install recent updates into our system repositories. To do that you need to use the following command in our terminal.

$ sudo apt update && apt upgrade -y

2. Uninstall old Docker versions

If you have ever installed Docker before you need to uninstall them to allow the new Docker-CE to be installed. To do uninstallation, run the following command in your terminal.

$ sudo apt remove docker

3. Install Docker-ce on Ubuntu 20.04

To begin installing docker-ce, run the following command on your terminal. It will install docker with its dependencies.

$ sudo apt install docker.io

You will get the following sample output on your terminal.

Output
The following additional packages will be installed:
  bridge-utils containerd dns-root-data dnsmasq-base libidn11 pigz runc ubuntu-fan
Suggested packages:
  ifupdown aufs-tools cgroupfs-mount | cgroup-lite debootstrap docker-doc rinse zfs-fuse | zfsutils
The following NEW packages will be installed:
  bridge-utils containerd dns-root-data dnsmasq-base docker.io libidn11 pigz runc ubuntu-fan
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 74.5 MB of archives.
After this operation, 361 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

Press Y to allow installation to continue.

Check the version of docker installed with the following command.

$ docker version
Client:
 Version:           20.10.7
 API version:       1.41
 Go version:        go1.13.8
 Git commit:        20.10.7-0ubuntu5~20.04.2
 Built:             Mon Nov  1 00:34:17 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.8
  Git commit:       20.10.7-0ubuntu5~20.04.2
  Built:            Fri Oct 22 00:45:53 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.5.5-0ubuntu3~20.04.1
  GitCommit:        
 runc:
  Version:          1.0.1-0ubuntu2~20.04.1
  GitCommit:        
 docker-init:
  Version:          0.19.0
  GitCommit:        

4. Enable Docker-ce

We need to enable docker-ce to start on reboot, in order to avoid starting every time you boot your machine.

$ sudo systemctl enable docker

5. Start Docker-ce service

You are supposed to start the docker service to run containerd environment. To start, use the following command.

$ sudo systemctl start docker

Lastly, we can check the status of docker to see if it is running.

6. Check status of Docker-ce

Check if Docker is running with the following command on your terminal.

$ sudo systemctl status docker

If you got status active, then your docker service is running as expected, if not probably you haven’t started the service.

Output
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-01-01 08:25:22 UTC; 2min 0s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 15639 (dockerd)
      Tasks: 8
     Memory: 50.2M
     CGroup: /system.slice/docker.service
             └─15639 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Jan 01 08:25:21 ubuntu dockerd[15639]: time="2022-01-01T08:25:21.900771603Z" level=warning msg="Your kernel does>
Jan 01 08:25:21 ubuntu dockerd[15639]: time="2022-01-01T08:25:21.900788697Z" level=warning msg="Your kernel does>
Jan 01 08:25:21 ubuntu dockerd[15639]: time="2022-01-01T08:25:21.900798067Z" level=warning msg="Your kernel does>
Jan 01 08:25:21 ubuntu dockerd[15639]: time="2022-01-01T08:25:21.901620999Z" level=info msg="Loading containers:>
Jan 01 08:25:22 ubuntu dockerd[15639]: time="2022-01-01T08:25:22.031254578Z" level=info msg="Default bridge (doc>
Jan 01 08:25:22 ubuntu dockerd[15639]: time="2022-01-01T08:25:22.117928719Z" level=info msg="Loading containers:>
Jan 01 08:25:22 ubuntu dockerd[15639]: time="2022-01-01T08:25:22.188902438Z" level=info msg="Docker daemon" comm>
Jan 01 08:25:22 ubuntu dockerd[15639]: time="2022-01-01T08:25:22.189323611Z" level=info msg="Daemon has complete>
Jan 01 08:25:22 ubuntu systemd[1]: Started Docker Application Container Engine.
Jan 01 08:25:22 ubuntu dockerd[15639]: time="2022-01-01T08:25:22.235122738Z" level=info msg="API listen on /run/>
lines 1-21/21 (END)

7. Test Docker-ce

Let’s test our docker to see if it is running. Test using hello-world container.

$ docker run hello-world
Output
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
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/

You can also search docker images available on the Docker hub. Let’s search for Ubuntu images available for example.

$ docker search ubuntu

You will get the following output

ubuntu                                                    Ubuntu is a Debian-based Linux operating sys…   13421     [OK]       
dorowu/ubuntu-desktop-lxde-vnc                            Docker image to provide HTML5 VNC interface …   598                  [OK]
websphere-liberty                                         WebSphere Liberty multi-architecture images …   282       [OK]       
rastasheep/ubuntu-sshd                                    Dockerized SSH service, built on top of offi…   256                  [OK]
consol/ubuntu-xfce-vnc                                    Ubuntu container with "headless" VNC session…   243                  [OK]
ubuntu-upstart                                            DEPRECATED, as is Upstart (find other proces…   112       [OK]       
ansible/ubuntu14.04-ansible                               Ubuntu 14.04 LTS with ansible                   98                   [OK]
neurodebian                                               NeuroDebian provides neuroscience research s…   88        [OK]       
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5      ubuntu-16-nginx-php-phpmyadmin-mysql-5          50                   [OK]
open-liberty                                              Open Liberty multi-architecture images based…   48        [OK]       
ubuntu-debootstrap                                        DEPRECATED; use "ubuntu" instead                45        [OK]       
i386/ubuntu                                               Ubuntu is a Debian-based Linux operating sys…   28                   
nuagebec/ubuntu                                           Simple always updated Ubuntu docker images w…   24                   [OK]
1and1internet/ubuntu-16-apache-php-5.6                    ubuntu-16-apache-php-5.6                        14                   [OK]
1and1internet/ubuntu-16-apache-php-7.0                    ubuntu-16-apache-php-7.0                        13                   [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mariadb-10   ubuntu-16-nginx-php-phpmyadmin-mariadb-10       11                   [OK]
1and1internet/ubuntu-16-nginx-php-5.6-wordpress-4         ubuntu-16-nginx-php-5.6-wordpress-4             9                    [OK]
darksheer/ubuntu                                          Base Ubuntu Image -- Updated hourly             5                    [OK]
1and1internet/ubuntu-16-nginx-php-7.0                     ubuntu-16-nginx-php-7.0                         4                    [OK]
owncloud/ubuntu                                           ownCloud Ubuntu base image                      3                    
1and1internet/ubuntu-16-nginx-php-7.1-wordpress-4         ubuntu-16-nginx-php-7.1-wordpress-4             3                    [OK]
1and1internet/ubuntu-16-sshd                              ubuntu-16-sshd                                  1                    [OK]
1and1internet/ubuntu-16-php-7.1                           ubuntu-16-php-7.1                               1                    [OK]
smartentry/ubuntu                                         ubuntu with smartentry                          1                    [OK]
1and1internet/ubuntu-16-rspec                             ubuntu-16-rspec                                 0                    [OK]

Running a Docker Container

Lets ru a container with the following command;

$ docker run -it ubuntu

-it gives interactive shell access to the container

$ docker run -it fedora 

It will pull the fedora image from the Docker Hub.

Output
Unable to find image 'fedora:latest' locally
latest: Pulling from library/fedora
edad61c68e67: Pull complete 
Digest: sha256:40ba585f0e25c096a08c30ab2f70ef3820b8ea5a4bdd16da0edbfc0a6952fa57
Status: Downloaded newer image for fedora:latest

From here you can do anything with Fedora distro. As an example lets do an update inside the container.

$ sudo dnf update -y

8. Conclusion

From here you can see our Docker-CE is running as expected, Learn other docker commands to be well conversant with docker. Docker Documentation has a tone of information.

About Kipkoech Sang

I am a technology enthusiast who loves to share gained knowledge through offering daily tips as a way of empowering others. I am fan of Linux and all other things open source.
View all posts by Kipkoech Sang →

1 thought on “How to install and configure Docker-CE on Ubuntu 20.04

Leave a Reply

Your email address will not be published.