Tips on how to Set up Docker on Ubuntu Linux

Docker has taken the software development industry by storm, not only revolutionizing the way we ship and deploy software, but also changing the way engineers set up software development environments on their computers.

This guide will show you how to get started with Docker by installing it on Ubuntu Linux 20.04 (Focal Fossa), the latest LTS (Long Term Support) version of Ubuntu at the time of this writing.

Advantages of Docker

Docker is an open source platform with which you can automate and provide applications as independent packages, so-called containers. Docker uses the virtualization technology of the operating system, but unlike virtual machines it saves system resources considerably.

Some of the main advantages of Docker are:

  • Relatively easy to use and learn

  • Provides a consistent and easy way to deploy software

  • Compatible with microservice architecture

  • Very little resource consumption

Set up the Docker software repository

There are several methods for installing Docker. This guide shows you how to install Docker from the Docker repositories using the apt command utility. If you install Docker this way, you can easily update the Docker package in the future. This is also recommended by the Docker team.

The first step in the installation is to add the Docker software repository to your list of software sources. You use the Docker software repository over HTTPS and then install the required software with the following command.

First, update your list of available software packages.

sudo apt update

Then download all the necessary dependencies for the installation apt install.

sudo apt install apt-transport-https ca certificates lure gnupg lsb-release

The Docker software uses GnuPG, also known as GPG, to secure communication when downloading software packages from the repository. GPG is an implementation standard of PGP (Pretty Good Privacy) that is used to encrypt messages or data.

Use the following command to add the official Docker GPG key to your local key rings.

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

Docker has three major versions of the software version in its software repositories: the stable version, the trial version, and the nightly release version. This guide describes the stable release version of Docker.

Run the following command to use the stable repository release version of Docker.

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

Note: The above command assumes that you are using the AMD architecture. If you happen to be using the ARM architecture, you can replace the word arch = amd64 in the above command with arch = arm64, or arch = armhf if you are using Arm Hard Float.

Install the Docker Engine

Now that you've set up the Docker software repository, you can proceed with installing the Docker Engine, which is the core of managing and running Docker containers. Other important components of the Docker Engine are Docker Client, Containerd, RunC and the Docker daemon.

Make sure to update your package sources using the command below as you recently added the Docker repository to your list of software sources.

sudo apt update

Run the following command to install the Docker Engine. The command installs the latest stable version of Docker Engine by default.

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

If you want to install a specific version of Docker, you can first check the list of available versions with the following command.

apt-cache madison docker-ce

You can then install the specific version of Docker with the command below. For example to install 5: 10/20/6 ~ 3-0 ~ Ubuntu focus::

sudo apt-get install docker-ce = 5: 20.10.6 ~ 3-0 ~ ubuntu-focal docker-ce-cli = 5: 20.10.6 ~ 3-0 ~ ubuntu-focal

Confirm installation

To verify that Docker was installed successfully, you can run the following command and print out the version number of the Docker Engine installed.

Docker -v

On Ubuntu Linux and most Debian-based distributions, the Docker service starts automatically when your system starts.

You can try to do that Hello World Docker image to test the installation. Since the image is not available locally on your computer, the system downloads it from Docker Hub, a library of container images. The next time you run the image again, the local copy that is on your PC will be used.

Sudo Docker run Hello World

Run Docker as a non-root user

At the moment you can only run Docker containers as superuser, that's why sudo is used in the above command. The Docker daemon is tied to a Unix socket that by default belongs to the root user, and non-root users can only access it via sudo.

In order to be able to run Docker containers and other important commands without being a superuser, you first need to create a user group called docker Then add your user to the Docker group on your computer. The groupadd Command is responsible for managing user groups on Linux.

Sudo Groupadd Docker

sudo usermod -aG docker $ USER

Use the following command to enable group changes.

Newgrp Docker

Note: Remember to log out and then back in so that the system can recognize the newly created group membership. You can use the following command to sign out.


In some cases you may need to restart your computer if you still cannot run the Docker command as a non-root user.

Uninstall Docker

Just run the following command to remove or uninstall the Docker Engine from Ubuntu Linux.

sudo apt Docker remove Docker engine Containerd Runc

Although the Docker Engine has been removed, other files associated with Docker such as images, containers, volumes or custom configuration files are not automatically removed. You can delete these files using the rm utility.

sudo rm -rf / var / lib / docker

sudo rm -rf / var / lib / Containerd

Docker in practice

This guide shows you how to install and configure Docker on Ubuntu Linux. It also shows you how to run a simple Docker image that is obtained from the Docker Hub.

Docker is a very versatile tool and has many use cases in software development. If you are a software developer or work in DevOps, Docker makes it easy to deploy software in different environments and is useful for testing and prototyping software.

6 reasons to use Docker virtualization software

Docker offers many advantages over a virtual machine – here are why you should use it today.

Continue reading

About the author

Mwiza Kumwenda
(6 articles published)

Mwiza is a professional developer of software and writes extensively on Linux and front-end programming. Some of his interests include history, economics, politics, and enterprise architecture.

By Mwiza Kumwenda

Subscribe to our newsletter

Sign up for our newsletter to receive tech tips, reviews, free e-books, and exclusive offers!

One more step …!

Please confirm your email address in the email we just sent you.

Leave a Reply

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