Installing Docker on Ubuntu
In this article we’ll install Docker on Ubuntu 18.04, 20.04 and 22.04. We’ll start with the prerequisites, then walk through the installation itself.
Docker is an application that simplifies deploying, running and managing containers.
Here we install Docker Community Edition (Docker CE) on Ubuntu 22.04, 20.04 and 18.04.
Prerequisites
Before installing Docker on Ubuntu, check the following.
Supported operating systems
Docker Engine needs one of these 64-bit Ubuntu versions:
- Ubuntu Kinetic 22.10
- Ubuntu Jammy 22.04 (LTS)
- Ubuntu Focal 20.04 (LTS)
- Ubuntu Bionic 18.04 (LTS)
Docker Engine supports these architectures:
- x86_64 (amd64)
- armhf
- arm64
- s390x
Remove old versions of Docker
Older versions of Docker may be installed under names such as docker, docker-engine or docker.io, and you may also have containerd or runc. Before installing the new version, remove them all with:
sudo apt-get remove docker docker-engine docker.io containerd runc
apt may report that none of these packages are installed; that’s fine.
Images, containers, volumes and networks stored in /var/lib/docker/ aren’t removed automatically. If you want a completely clean installation, delete that directory too.
Installing Docker on Ubuntu
There are several ways to install Docker on Ubuntu. In this article we use the official repository.
Set up the Docker repository
Before installing Docker Engine on a new machine for the first time, you need to set up the Docker repository. After that, you can install and update Docker from it.
1. Update apt and install the packages that let it use a repository over HTTPS:
sudo apt-get update
sudo apt-get install
ca-certificates
curl
gnupg
2. Add Docker’s official GPG key:
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
3. Add the repository:
echo
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker Engine
1. Update the apt package index:
sudo apt-get update
2. Install Docker Engine, containerd and Docker Compose. This installs the latest version; if that’s what you want, skip ahead to step 3.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
To install a specific version instead, first list the versions available in the repository:
apt-cache madison docker-ce | awk '{ print $3 }'
Then install the version you want. For example, this installs version 5:20.10.13~3-0~ubuntu-jammy:
VERSION_STRING=5:20.10.13~3-0~ubuntu-jammy
sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin
3. Check that Docker Engine is installed correctly
sudo docker run hello-world
This downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.
Docker Engine is now installed and running. Installing Docker on Ubuntu also creates a docker group, but no users are added to it, so you need to run Docker commands with sudo. You can allow other users to run Docker commands and customize the setup after installation, but we won’t cover that here.
Uninstalling Docker Engine
To remove Docker Engine from Ubuntu:
1. Remove the Docker Engine, CLI, containerd and Docker Compose packages:
sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
2. Images, containers, volumes and custom configuration files aren’t removed automatically. To delete all images, containers and volumes, run:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
Remove any custom configuration files manually if you want to.
With a cloud server from Mizbandade, you can easily install and run Docker on your own server.

