install docker on ubuntu

Install docker on ubuntu | complete tutorial in 2022

With each passing day popularity of Docker is also increasing. Docker is an open-source tool and is available for all operating systems. In this tutorial, we will understand how we can install Docker on Ubuntu. So let’s get started.

Install docker on ubuntu

Install docker on ubuntu

In this session, we will understand how to install docker on an ubuntu system.

Install docker on ubuntu by setting up docker repositories

There are many ways to install Docker on Ubuntu, and In this tutorial, I will explain how to install Docker by setting up the docker repositories.

Before installing Docker on Ubuntu, it is recommended to uninstall any old version of docker, or docker-engine. Type the below command to remove old docker packages.

sudo apt-get remove docker docker-engine containerd runc
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package docker-engine

Once all the docker packages are uninstalled, let’s proceed further and update all ubuntu packages.

sudo apt-get update
Get:1 focal-security InRelease [114 kB]
Hit:2 focal InRelease
Get:3 focal-updates InRelease [114 kB]
Get:4 focal-backports InRelease [101 kB]
Fetched 328 kB in 13s (24.4 kB/s)
Reading package lists... Done

Now install other packages to allow apt to use of a repository over HTTPS

sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
Reading package lists... Done
Building dependency tree
.................<supressed o/p>.............
.................<supressed o/p>.............
Do you want to continue? [Y/n] y
Get:1 focal-updates/main amd64 distro-info-data all 0.43ubuntu1.5 [4656 B]
.................<supressed o/p>.............
.................<supressed o/p>.............
Setting up gpg-wks-server (2.2.19-3ubuntu2.1) ...
Setting up gpg-wks-client (2.2.19-3ubuntu2.1) ...
Setting up gnupg (2.2.19-3ubuntu2.1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...

press y to continue the installation.

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=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

and update all ubuntu packages by typing the below command.

sudo apt-get update
Get:1 focal InRelease [52.1 kB]
Hit:2 focal InRelease
Get:3 focal/stable amd64 Packages [10.6 kB]
Hit:4 focal-security InRelease
Hit:5 focal-updates InRelease
Hit:6 focal-backports InRelease
Fetched 62.7 kB in 12s (5370 B/s)
Reading package lists... Done

Finally, Install Docker and docker-cli, and other docker packages.

sudo apt-get install docker-ce docker-ce-cli
Reading package lists... Done
Building dependency tree
Reading state information... Done
.................<supressed o/p>.............
.................<supressed o/p>.............
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.
Processing triggers for systemd (245.4-4ubuntu3.7) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...

Awesome, we have installed all the necessary docker packages. Now let’s start the docker service by typing the below command:

sudo service docker start
 * Starting Docker: docker                                                                                                                                                                           [ OK ]

Verify if the docker service starts.

sudo service docker status
 * Docker is running

Finally, pull a hello-world docker image and verify the output.

docker run hello-world 
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
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.
 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:

For more examples and ideas, visit:

Awesome you have successfully installed docker in your system. You can check my other blogs to


I hope this tutorial helps you to install Docker on the ubuntu system. Please do let me know if you face any issues while installing Docker.

More to Read?

Understand docker logs

Docker layers

Which docker base image to use

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top