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.
Table of Contents
Install Docker CE on Ubuntu 20.04
The exits two editions of docker available.
Docker CE and
- 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 on Ubuntu 20.04;
- Installing Docker CE on Ubuntu 20.04 from Docker Repositories
- Installing Docker CE manually using the DEB binary package
- Installing Docker CE using Docker Installation Script (Beyond the scope of this tutorial).
Installing Docker CE on Ubuntu 20.04 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 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.
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
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
containerd.io, you would simply pull them as follows;
You can then install them using the
dpkg package manager. Be sure to install
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 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
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.