How to install Docker on Ubuntu/Linux?

Install Docker on Ubuntu

Docker is an open-source containerization platform that allows developers to build, test, and ship applications in packaged and isolated environments called containers. In the recent few years, the use of Docker has seen tremendous growth among all types of organizations. If you are still wondering what Docker actually is, check out our guide on What is Docker? to gain an in-depth insight. In this article, we will discuss a complete step-by-step guide on how to install Docker on Ubuntu or any other Linux machine.

There are two versions of Docker that are available in the market today. These are – Docker CE (Community Edition) and Docker EE (Enterprise Edition). If you are new to Docker and just looking to use it for a small-scale project or for testing purposes, you can go ahead with the Docker Community Edition.

Before we move ahead and discuss how to install Docker on Ubuntu, let’s check out the prerequisites of installing Docker.

Also, check out our complete tutorial on Docker.

Prerequisites to Install Docker on Ubuntu

If you want to install Docker on Ubuntu, you need to have a 64-bit version of the following Ubuntu distributions.

  • Hirsute 21.04
  • Ubuntu Groovy 20.10
  • Ubuntu Focal 20.04 (LTS)
  • Bionic 18.04 (LTS)
  • Xenial 16.04 (LTS)

Moreover, the Docker Engine is well supported on most of the architectures including arm64, x86_64, amd64, armhf, etc.

Also, you will need access to sudo privileges or root account along with the terminal.

Uninstall Previous Versions of Docker on Ubuntu (If Any)

There are many methods to install Docker on Ubuntu/Linux. But before we move ahead, you need to first remove any pre-installed version of Docker on your Ubuntu machine. The older versions of Docker were named as one of the following – docker,, docker-engine, etc. To do so, you can execute the following commands.

$ sudo apt-get remove docker docker-engine containerd runc
Uninstall Docker from Ubuntu

If the apt-get reports that no such packages were found, it means that there are no older versions of Docker installed previously on your Ubuntu/Linux machine.

Next, you need to uninstall Docker-Engine, containerd, CLI packages from your Ubuntu machine if it was previously installed.

$ sudo apt-get purge docker-ce docker-ce-cli

Docker images, containers, network, volumes, and other configuration files are preserved even after uninstalling Docker. They reside in the directories /var/lib/docker and /var/lib/containerd. To remove them, use the commands below.

$ sudo rm -rf /var/lib/docker
$ sudo rm -rf /var/lib/containerd

Now, let’s discuss the different methods to install Docker on Ubuntu.

How to Install Docker on Ubuntu?

Method 1. Installing Docker on Ubuntu using Repositories

Let’s check out how to install Docker on Ubuntu manually using the official repositories.

Step 1. Updating the apt package index.

The first step is to update the Linux Machine. If you are using an Ubuntu machine, you can simply run an apt update using the specified command.

$ sudo apt-get update
Install Docker on Ubuntu step 1
Updating the apt package index

Step 2. Installing packages to allow the apt to use a repository over HTTPS.

We will need these packages to do so.

  • apt-transport-https – It lets the package manager transfer files and data over HTTPS.
  • ca-certificates – It lets the web browser and system check security certificates.
  • curl – It transfers the data.
  • software-properties-common – It adds scripts to manage the software.

The command to install these is –

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
step 2
Install Prerequisite Packages

Step 3. Add the offical GPG key of Docker.

$ curl -fsSL | sudo apt-key add -
Install Docker on Ubuntu step 3
Add Docker GPG key

Step 4. Add the repository.

The fourth step is to add the Docker repositories. It will make the installation process much easier. It enables us to use the officially supported method of the installation.

$ sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"
step 4
Adding the Repository

Step 5. Installing the Docker-Engine, Containerd, and CLI.

Now that we have added and enabled the repository, we can go ahead and install the latest version of Docker on our Ubuntu machine. To do so, we need to first update the apt index and then, we can install the latest version of Docker-Engine, Containerd, and CLI.

$ sudo apt update
$ sudo apt install docker-ce
Install Docker on Ubuntu step 5
Installing Docker-Engine

Step 6. To install a specific version of Docker

If you want to install a specific version of Docker on your Ubuntu machine, you need to first list all the version that are available in the repo. Then, select the version you want to install.

$ apt-cache madison docker-ce
step 6
List Docker Versions

Use the version string in the 2nd column, to install the specific version.

Replace <VERSION_STRING> with the specific version.

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

Step 7. Verify the Installation

To check the status of the Docker service, execute the following command.

$ systemctl status docker
Install Docker on Ubuntu step 7
Docker Installation Verification

Please note that if you get any error such as “Failed to start Docker Application Container Engine”, then try executing the commands below to restart the Docker service.

$ systemctl daemon-reload
$ systemctl restart docker.service
$ systemctl status docker

Step 8. Running Docker without Sudo

If you don’t want to preface the docker command with sudo, you can simply create a Unix group with the name docker and try to add your users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group.

To create the Docker group, you can execute the command below.

$ sudo groupadd docker

Next, you can add the user to the group.

$ sudo usermod -aG docker $USER
Install Docker on Ubuntu step 8
Add user to Docker group.

Step 9. Running a hello-world Docker container

Let’s try to run a hello-world Docker container without using sudo to check whether or not the Docker service is running actively in our Ubuntu machine.

$ docker run hello-world
 step 9
Running a hello-world container

To upgrade Docker, you can simply use the following command.

$ sudo apt-get update && apt-get upgrade

Method 2. Install Docker on Ubuntu using a .deb Package

If you are not able to install Docker from the official Docker repository, you can install it manually by downloading the .deb package. In this case, to update Docker, you will need to manually install the newer version everytime.

Navigate to the address and choose the version of your ubuntu machine. Next, navigate to /pool/stable, choose the architecture and download the debian file.

To install the Docker Engine, execute the command below. You need to replace the path from the path where you have downloaded the debian package.

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

This will automatically start the docker daemon.

To verify the installtion, run the hello-world container.

$ sudo docker run hello-world

Method 3. Install Docker on Ubuntu using a Convenience Script

On the off-chance that both the above-mentioned methods to install Docker on Ubuntu are not working for you, you can install it using a convenience script as well. Docker provides this script at the URLs and With the help of this script, you can install the testing or edge versions of the community edition of the Docker engine.

You can find the source code of this script in the docker-install repository. Please note that it is not recommened to use this script to install Docker on Ubuntu for production environments due to the several security risks that it posseses.

You can use the below commands to do so.

$ curl -fsSL -o
$ sudo sh

Wrapping Up!

To conclude, in this article, we have discussed three different methods to install Docker on Ubuntu/Linux machines. These included installing Docker with the help of an official repository, Debian packages, and convenience scripts. We hope that you will now be able to start with your Docker journey the best possible way. To ensure this, we have the complete Docker Tutorials for you which are well-crafted by the industry experts on Docker.

If you have any query, suggestion, or doubt, please mention it on the comments. Our expert will get back to you with the solution. If you liked this article, please give a thumbs up in the comments. Our users’ happiness is what drives us to create quality content like this article on How to install Docker on Ubuntu/Linux?

Happy Learning!

One comment

Leave a Reply