How to Install Docker in Ubuntu?

Photo of author

By admin

Docker is one of the most popular software when it comes to creating containers for application development. While dockers share the same idea as that virtual machines, they offer better flexibility.

Docker can readily speed up the entire application, requiring very few resources from the host’s kernel. In this tutorial, we are going to discuss how to install Docker in Ubuntu. You will learn the various ways to install Docker Engine and use it in the safest way.

Prerequisites for Installing Docker on Ubuntu

1. Supported OS

You can easily install Docker Engine on any of the following 64-bit versions of Ubuntu:

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

2. Storage Drives

Storage drives that are supported on Ubuntu include opverlay2, btrfs, and aufs.

3. Docker Hub Account (Optional)

Although having a Docker Hub account is completely optional, it is required if you want to publish your own images on it.

Installation Methods for the Docker Engine

Mainly, you can install Docker Engine on Ubuntu in one of the following 3 ways:

  1. A majority of the users go with installing Docker via the repository. It offers a seamless installation process without any hassles.
  2. If you want to take more control over the installation process, there’s always the option of downloading the DEB file. Once you have downloaded the file, you can install it in systems without an active internet connection.
  3. If you want to install the under-testing version for the development environment, you can always use the convenience script.

How to Install Docker in Ubuntu?

1. Installing Docker using the Repository

Setting up the repository is the prime thing that you need to do before installing your Docker Engine. You can install or update. Only after that, Docker can be installed from the repository. Here is the process to set up the Docker repository:

Step #01 – You need to update the apt package and install the apt. The apt command ensures that the repositories can take over the standard HTTPS installation.

$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \

Step #02 – After that, you need to add Docker’s GPG key as:

$ curl -fsSL | sudo apt-key add - 

Step #03 – After that, you need to verify it. That verification will provide you with the key to the fingerprints. 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88. You need to add only the last eight characters.

$ sudo apt-key fingerprint 0EBFCD88
pub rsa4096 2017-02-22 [SCEA]
  9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid  [ unknown] Docker Release (CE deb) <>
sub rsa4096 2017-02-22 [S]

Step #04 – After that, you need to build a stable repository by using the following command. If you want to add the test repository, you must replace the word stable with the test.

Also, you need to note that the subcommand which is stated below returns your Ubuntu distribution. Docker does not hold any guarantee for the untested distributions.

$ sudo add-apt-repository \
 "deb [arch=amd64] \
 $(lsb_release -cs) \

This is for amd64. For deb_armhf and deb_arm64, you need to replace amd64 in the command with the one you want.

Installing the Docker Engine

Well, installing a Docker Engine can be done by installing the latest version after updating the apt package.

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

Also, if you have multiple repositories installed, then the most recent version of the Docker Engine will automatically be installed. You need to follow the following steps to install a specific version:

Step #01 – While installing a specified version, you can always look at the available repositories. After that, select and install.

$ apt-cache madison docker-ce
 docker-ce | 5:18.09.1~3-0~ubuntu-xenial | xenial/stable amd64 Packages
 docker-ce | 5:18.09.0~3-0~ubuntu-xenial | xenial/stable amd64 Packages
 docker-ce | 18.06.1~ce~3-0~ubuntu  | xenial/stable amd64 Packages
 docker-ce | 18.06.0~ce~3-0~ubuntu  | xenial/stable amd64 Packages

Step #02 – Select the column from which you wish to install a specific version.

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

Step #03 – You can always run the hello world image to properly check the installation.

$ sudo docker run hello-world

It will run in a container. After that, it will print a piece of information and exit.

Note: Docker Engine is now installed and running. Even after creating the docker group, you need to add users. For other configurational steps, and to allow a non-privileged user to run the Docker Commands, you need to proceed to Linux post-install.

How to Upgrade the Docker Engine?

To upgrade, you need to run sudo apt-get update, and after that, you need to follow the installation instructions and choose the new version to install.

2. Install from a Package

You can also install the Debian (DEB) file and install it manually without using the Docker repository. Proceed further with the following steps:

Step #01 – Go to and choose your Ubuntu version.

Step #02 – Browse to pool/stable/ and choose amd64, arm64 and armhf.

Step #03 – Download the .deb file for the corresponding version. If you need to install the test package, change the word ‘stable’ from ‘test’. After that, you need to change the below path to the directory of the downloaded Docker package.

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

This will automatically start the Docker daemon.

Step #04 – Run the hello world script in order to verify the installation process.

$ sudo docker run hello-world

This will run a container. While running, it will print an informative message and exit.

Now that, you have got your Docker engine installed, but no user is added to the newly created docker group. In this case, you need to proceed to the Linux post-installation steps for further configurations.

Upgrading the Docker Engine

You need to install new files every time to install the latest Docker Engine and need to repeat the same installation process with the new file.

3. Install via a Convenience Script

You can install Docker Engine from the convenience scripts provided by Docker. You can get the scripts from and

You can always go with these scripts to install either edge or testing versions. But it has its risks, and you need to understand them before opting to install. It is always advised to run these scripts in development environments. The risks are:

  • You need to cautiously audit the scripts as they need sudo privileges to run.
  • Scripts will tend to configure your Linux distribution system.
  • The scripts will always install the current version. There’s nothing you can do about it.
  • You must not use the scripts if your host machine has Docker preinstalled.
  • It can install a large number of the packages as it does not ask for confirmation.

The following is a script that will install the Docker Engine. You should always examine the scripts. If you want a test version, replace ‘get’ with ‘test’.

$ curl -fsSL -o
$ sudo sh

<output truncated>

You can always add users to the Docker group with the following command:

sudo usermod -aG docker <your-user>

It will take effect after you log out and log back in. Now the Docker Engine community is created and it will start on a .deb-based distribution.

For RPM-based distribution, you should use commands like systemcl or service. You can’t run the Docker command without admin privileges.

Upgrade the Docker Engine

You can upgrade your Docker Engine using your package manager directly. If you re-run the convenience scripts, it will re-install the previously installed repositories.

Uninstalling the Docker Engine from Ubuntu

In case you do not want Docker Engine on your Ubuntu device, you can remove it by following these steps:

Step #01 – You can use the below command to uninstall Docker Engine on Ubuntu

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

Step #02 – You have to manually delete the remaining images and the containers. In case, you have edited any configuration files; you need to delete them manually as well.

$ sudo rm -rf /var/lib/docker

Final Takeaway

That was all about how to install Docker on Ubuntu. You can easily choose among the 3 aforementioned ways to get started with Docker on your Ubuntu-based device.

Ensure to pay close attention to the above-mentioned steps, and you can easily install Docker Engine on your system running Ubuntu. Leveraging Docker for DevOps technologies will deliver you a seamless workflow. So, all the best!

People are also reading:

Frequently Asked Questions (FAQs)

1. How do I install and start Docker?

You need to first install Docker Engine by changing the path given below to the path where you downloaded the Docker package. 

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

The Docker daemon will start automatically.

Once done, verify that the Docker Engine is installed correctly by running the hello-world image i.e. 

$ sudo docker run hello-world

  • How to use the docker run command?

Here is how you can use the docker run command:

  • Run a Container Under a Specific Name.
  • Run a Container in the Background (Detached Mode) 
  • Run a Container Interactively.
  • Run a Container and Publish Container Ports.
  • Run a Container and Mount Host Volumes.
  • Run a Docker Container and Remove it Once the Process is Complete.

2. What is the Docker Run command?

Docker enables you to run a container in interactive mode. The docker run command creates a container from a given image and starts the container using the specified command. 

3. How do I start an Ubuntu container?

Follow the below-given steps to start an Ubuntu container:

Step 1: Install the Docker application on the Ubuntu server.

Step 2: Run the CentOS Docker image.

Step 3: Run the image in interactive mode by using the -it option.

Step 4: Run the /bin/bash command as the initial process.

4. Why is Docker used?

Docker is an open-source containerization platform that is used by developers to package applications into containers. Containers are standardized units that have everything the software needs to run including code, system tools, libraries, and runtime.

5. Where is the Docker terminal located in Windows?

Once you have installed Docker on your Windows system, you can locate it from the Start menu. Click on the Start menu, and select the Docker icon from the hidden icons menu of your taskbar. Right-click on the icon to view the Docker commands menu. Select “Settings”, and then make sure that “Use the WSL 2-based engine” is checked in Settings > General.

Leave a Comment