How do I install docker in Ubuntu 20.04? In this guide we are going to install docker in Ubuntu 20.04.
Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels.
Note: Ubuntu 20.04 LTS (Focal Fossa) reached the end of its standard five-year support on 31 May 2025. The steps below still work, but for new deployments prefer a supported release such as Ubuntu 24.04 LTS (Noble Numbat). If you must stay on 20.04, keep it patched with Ubuntu Pro (ESM).
Related Posts
- How to install and configure Docker in Fedora 34/35
- How to install and configure Docker on Debian 11
- How to install and configure Docker in CentOS 8
- Getting Started With Docker Compose With Examples
- Docker as a build agent – Run Jenkins builds on Docker
Prerequisites
To follow along, ensure you have:
- An Ubuntu 20.04 system
- Internet access from the system
- Root access or user with sudo access
Table of Content
- Ensure your system packages are up to date
- Uninstall previous versions if any
- Install docker engine using the repository
- Install docker engine from a package
- Install using the convenience script
- Verify installation
- Executing the Docker Command Without Sudo
- Uninstalling docker when it’s no longer needed
1. Ensure your system packages are up to date
Before proceeding, let us ensure your packages are updated
| |
2. Uninstall previous versions if any
Packages providing older versions of Docker are docker, docker.io, or docker-engine.
Let us use this command to ensure that these packages do not exist in our system:
| |
It’s OK if apt-get reports that none of these packages are installed.
Installing docker
You can install Docker Engine in different ways, depending on your needs:
- You can set up docker repositories and install docker using apt
- You can download the DEB packages and install manually
- You can choose to use automated convenience scripts to install Docker
3. Install docker engine using the repository
On a new host, the docker repositories do not exist. For the first time on a new host machine, you need to set up the Docker repository. Afterwards, you can install and update Docker from the repository.
Let us install the following packages to allow apt to use a repository over HTTPS:
| |
Add Docker’s official GPG key:
| |
Use the following command to set up the stable repository.
| |
Docker’s current docs place the key at
/etc/apt/keyrings/docker.ascinstead of/usr/share/keyrings. Either location works as long as thesigned-by=path in the.listfile points to where you saved the key.
Install Docker Engine
Update the apt package index since we added a new repository:
| |
Now let’s install the latest version of Docker Engine, containerd, and the Buildx and Compose plugins:
| |
The
docker-compose-pluginpackage installs Compose v2, which you invoke asdocker compose(no hyphen). The old standalonedocker-compose(v1) is deprecated.
Optional: Installing a specific version
If you have requirements that necessitate a specific version, you can do so.
To install a specific version, list the versions available in your repo:
| |
Sample output:
| |
The versions shown above are from 2021 and are only illustrative; your system will list the current Docker releases.
Now you can install a specific version using the version string from the second column, for example, 5:19.03.9~3-0~ubuntu-focal.
| |
Example:
| |
4. Install docker engine from a package
If you cannot use Docker’s repository to install Docker Engine, you can download the .deb file for your release and install it manually. You need to download a new file each time you want to upgrade Docker.
Go to https://download.docker.com/linux/ubuntu/dists/, choose your Ubuntu version, then browse to pool/stable/, choose amd64, armhf, or arm64, and download the .deb file for the Docker Engine version you want to install.
Install Docker Engine, changing the path below to the path where you downloaded the Docker package.
| |
The Docker daemon starts automatically.
Verify that Docker Engine is installed correctly by running the hello-world image.
| |
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.
5. Install using the convenience script
Docker provides a convenience script at get.docker.com to install Docker into development environments quickly and non-interactively.
This example downloads the script from get.docker.com and runs it to install the latest stable release of Docker on Linux:
| |
6. Verify installation
Upon installation, docker will run as a daemon. To check that docker is running, we use the systemctl status docker command:
| |
The Active: active (running) shows that docker was started successfully.
We can run a hello-world image to test that docker works as expected:
| |
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.
I got this output, showing that it works fine:
| |
7. Executing the Docker Command Without Sudo
By default, the docker command can only be run by the root user or by a user in the docker group, which is automatically created during Docker’s installation process. If you attempt to run the docker command without prefixing it with sudo or without being in the docker group, you’ll get an output like this:
| |
If you want to avoid typing sudo whenever you run the docker command, add your username to the docker group:
| |
To apply the new group membership, log out of the server and back in, or type the following:
| |
You will be prompted to enter your user’s password to continue.
Confirm that your user is now added to the docker group by typing:
| |
I see this, confirming that I now belong to the docker group
| |
Now I can do docker. I can run the alpine image:
| |
We have successfully installed docker in our system!
8. Uninstalling docker when it’s no longer needed
To completely erase docker engine from the system, we need to uninstall the Docker Engine, CLI, and Containerd packages:
| |
Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:
| |
You must delete any edited configuration files manually.
Conclusion
In this guide we managed to install docker on our Ubuntu 20.04 system.