How To Install Docker on Ubuntu? – All About Docker Installation

Docker is a software platform that allows us to build, test and deploy applications easily. In this tutorial, we will discuss step by step guide to install docker on the Ubuntu machine.

Installation prerequisites

Before installing docker on Ubuntu we need to ensure the following prerequisites.

We need a 64 bit version any one of the Ubuntu version:

  • Impish – Ubuntu 21.10
  • Hirsute – Ubuntu 21.04
  • Focal – Ubuntu 20.04 (LTS)
  • Bionic – Ubuntu 18.04 (LTS)

Installation methods

We can install docker on Ubuntu using two methods.

  1. Install using repository (Recommended method)
  2. Install from package (offline method)

Let’s dive into the installation of docker on Ubuntu.

1.Install docker on Ubuntu using repository

This is the recommended method of docker installation on Ubuntu. First, we need to setup the docker repository in Ubuntu machine. After that we can install docker from the repository.

Run the following command to setup repository.

Update the package index and install necessary packages:

sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release

Add Docker’s official GPG Key:

curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Use the following command to set up the stable repository:

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Finally, we can install the docker engine using the following commands. We’ll update the package index and install the latest version of the docker engine and containerd using the below command.

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli

How to install a specific version of docker

Previously we have discussed the installation of the latest version of docker using a package repository. However, we can install a specific version using the following method.

First, we need to list all the versions available in the repository.

apt-cache madison docker-ce

Above command will list as shown below:

docker-ce | 5:20.10.12~3-0~ubuntu-focal | focal/stable amd64 Packages
 docker-ce | 5:20.10.11~3-0~ubuntu-focal | focal/stable amd64 Packages
 docker-ce | 5:20.10.10~3-0~ubuntu-focal | focal/stable amd64 Packages
 docker-ce | 5:20.10.9~3-0~ubuntu-focal | focal/stable amd64 Packages
 docker-ce | 5:20.10.8~3-0~ubuntu-focal | focal/stable amd64 Packages
 docker-ce | 5:20.10.7~3-0~ubuntu-focal | focal/stable amd64 Packages
 docker-ce | 5:20.10.6~3-0~ubuntu-focal |  

From the above output, we can install a specific version using the version string from the second column, for example, 5:20.10.7~3-0~ubuntu-focal (VERSION_STRING)

sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING>

Verify the docker engine installation by running hello-world image.

sudo docker run hello-world
Docker success full installation

From the above terminal output we can see docker is successfully installed.

2.Install docker from package

We can download docker .deb file and install it manually.

First go to and choose Ubuntu version , then browse to pool/stable/, choose amd64, armhf, arm64, or s390x, and download the .deb file for the Docker Engine version you want to install.

Downloaded Debian file can be installed using the following command.

sudo dpkg -i /path/to/package.deb

Verify docker engine by running hello-world image

sudo docker run hello-world

How to run docker without using sudo

We need to run docker with sudo command, but we can avoid it using the following steps.

First we need to create a docker group :

sudo groupadd docker

Add user to the docker group:

sudo usermod -aG docker $USER

Finally, log out and log back in to verify the installation by running the following command. If you are running this on virtual machine you need to restart the machine.

docker run hello-world


In conclusion, we have seen different ways to install docker on Ubuntu. Hope you enjoyed this tutorial. Learn about Ubuntu task manger here.

Leave a Comment