Install Docker CE on Ubuntu 20.04

|
Last Updated:
|
|

In this tutorial, we are going to learn how to install Docker CE on Ubuntu 20.04. Docker is a platform that enables developers and system administrators to build, run, and share applications in containers.

Installing Docker CE on Ubuntu 20.04

The exits two editions of docker available. Docker CE and Docker EE

  • Docker CE (Community Edition) is the open-source, community supported version of Docker and is available for free.
  • Docker EE (Enterprise Edition) is a commercial/premium version of Docker CE and is support by Docker Inc.

There are different methods in which you can install Docker CE;

Installing Docker CE from Docker Repositories

To install Docker CE from Docker, you first need to install some required packages by executing the command below. Some of the package may already be installed though;

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

Next, install Docker repository GPG signing key.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor > /etc/apt/trusted.gpg.d/docker.gpg

Install Docker repository on Ubuntu 20.04.

echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -sc) stable" \
> /etc/apt/sources.list.d/docker-ce.list

After that, update package cache.

apt update

Install Docker CE and other tools including containerd.io, An open and reliable container runtime.

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

Note that, even if you install just docker-ce package, other tools like docker-ce-cli and containerd.io will be installed along with it.

apt install docker-ce

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  aufs-tools cgroupfs-mount containerd.io docker-ce-cli pigz
The following NEW packages will be installed:
  aufs-tools cgroupfs-mount containerd.io docker-ce docker-ce-cli pigz
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 111 MB of archives.
After this operation, 401 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Installing Docker CE using DEB Binary Package

If you want to go the manual way, you can simply download Docker CE DEB binary package for your specific system version from https://download.docker.com/linux/ubuntu/dists/.

For example, in this case to download the DEB binary packages for Focal Fossa (Ubuntu 20.04), navigate to https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/ and grab the .deb files.

To download docker-ce, docker-ce-cli and containerd.io, you would simply pull them as follows;

wget https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/docker-ce_24.0.2-1~ubuntu.20.04~focal_amd64.deb
wget https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/docker-ce-cli_24.0.2-1~ubuntu.20.04~focal_amd64.deb
wget https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/containerd.io_1.6.21-1_amd64.deb

You can then install them using the apt or dpkg package manager. Be sure to install docker-ce-cli and containerd.io before docker-ce.

apt install ./docker-ce-cli_24.0.2-1~ubuntu.20.04~focal_amd64.deb
apt install ./containerd.io_1.6.21-1_amd64.deb
apt install ./docker-ce_24.0.2-1~ubuntu.20.04~focal_amd64.deb

Checking Installed Docker Version

To check the version of installed Docker, simply run the command;

docker --version
Docker version 24.0.2, build cb74dfc

Starting Docker Service

To start and enable Docker and Containerd service to run on system boot;

systemctl enable --now docker containerd

Running Docker as a non-root user

If you run Docker as standard system user, you may get such an error;

docker run hello-world
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: ...
/var/run/docker.sock: connect: permission denied.
See 'docker run --help'.

Therefore, if you need to run docker as non-root user, simply add the user you want to run docker as to docker group or simply, grant the user sudo rights. For example to add current user to docker group;

sudo usermod -aG docker $USER

Once you have added the user to the Docker group, log out and login again to have the user group membership re-evaluated.

You can then run docker as the standard user.

Verifying Docker CE installation

To verify that Docker CE is running well, you can try running the hello-world container image.

docker run hello-world

NOTE: If you still get the same permission denied error after adding user to docker group, logout and login again and you should be able to run docker as a standard user.


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

To list running containers;

docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
4083300e3660        hello-world         "/hello"            5 minutes ago       Exited (0) 5 minutes ago                       recursing_tereshkova

There you go. You have successfully installed Docker CE on Ubuntu 20.04. You can now explore Docker further.

Reference

Docker Engine Installation on Ubuntu

Other Tutorials

Monitor Docker Swarm Node Metrics using Grafana

Monitor Docker Containers Metrics using Grafana

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

2 thoughts on “Install Docker CE on Ubuntu 20.04”

Leave a Comment