How to Install Docker on Ubuntu 16.04 Linux

Update on:
Sep 5, 2021

Docker is an application use to simplify the application management process in containers, where containers use to run the application with the resource-isolated process. Docker allows you to build, test and deploy an application to run virtually anywhere.

It is similar to a virtual machine, more flexible, more resource-friendly, more portable, and more host operating system dependent. It is use to run a single application with a platform environment which includes everything needed by software to run.

Nowadays, Docker known as a modern software management platform includes DevOps continuous integration, deployment and production management.

In this tutorial, you will learn to install Docker on an Ubuntu 16.04 Linux system.

Docker packages are available under the Ubuntu 16.04 repositories, but it may not have the latest version. So, we will install the latest Docker here by using Docker’s official repositories.

Installing Docker on Ubuntu 16.04

The Docker installation on Ubuntu system or server is straightforward, enable the Docker repository and install packages after import the repository GPG key.

In the first step, we will update the package list and install the dependencies required to add new HTTPS repository:

$ sudo apt update
$ sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Now, import GPG key of Docker’s repository using the below curl command:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

After importing GPG key need to add Docker’s APT repository using the following command:

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Now, the Docker repository enabled in your system; you can install any version of Docker that is available in the current repositories.

Install latest version of Docker

To install the latest version of Docker you can use the below command, but if you want to install any specific version of Docker to install, you should skip this and go to the next one.

$ sudo apt update
$ sudo apt install docker-ce docker-ce-cli containerd.io

Install specific version of Docker

To install a specific version of Docker, you should have a list of the available version of Docker in your repository. To get the list of the available version of Docker, use the following command:

# sudo apt update
# apt list -a docker-ce

You will get the available version of Docker in the output of the command which is available in the second column.

docker-ce/focal 5:19.03.9~3-0~ubuntu-focal amd64

You can install specific version of Docker in your Ubuntu machine by mention version using “=<version>” after the package name, as shown below example:

$ sudo apt install docker-ce=<VERSION> docker-ce-cli=<VERSION> containerd.io

After successful installation, Docker service will start automatically. To verify the Docker service status use following command:

$ sudo systemctl status docker

The output should look like below:

● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2020-05-21 14:47:34 UTC; 42s ago

When a new version of Docker release for your machine you can update using following standard commands:

$ sudo apt update && sudo apt upgrade

If you don’t want to update Docker automatically, you should mark it as held back to prevent from being updated using the following command:

$ sudo apt-mark hold docker-ce

Execute Docker Commands as a Non-root user

The Docker commands are executable by only root user and a user with sudo privileges.

If you want to execute Docker command by a non-root user, first you need to add that user to the docker group that created during Docker CE package installation.

You can add a user in the docker group using the following command:

$ sudo usermod -aG docker $USER

You should replace “$USER” with the username.

Create a new user session to refresh the group membership, and the user is ready to execute the docker command.

Verify Docker Installation

To verify the Docker installed in the system, you can execute the docker command without sudo, and we’ll run a test container:

$ docker container run hello-world

The above command will download a test image if it is not available locally. After downloading run it in a container, print a “Hello from Docker” message and exit.

You will get the output similar to below:

This test container will stop after printing the message, as it is not having a long-running process.

Docker commands pull images from the Docker Hub; it is default cloud-based Docker’s registry service which has all other functionalities including stores Docker images in Private and Public repositories.

Uninstalling Docker

To uninstall Docker from the machine, always remove all containers, images, volumes, and networks.

You can stop all running containers and remove all docker objects using the following commands:

$ docker container stop $(docker container ls -aq)
$ docker system prune -a --volumes

Now, you can uninstall Docker package like any other packages from the Ubuntu system using the apt package manager:

$ sudo apt purge docker-ce
$ sudo apt autoremove


Now, you have learned to install Docker on Ubuntu 16.04 Linux machine and also learned to execute docker command and run a docker container. You can learn more about docker by following official Docker documentation.

If you have any questions related to docker, please leave a comment below.

Related Posts

How to Install CouchDB on Ubuntu 21.04 Linux Operating System

How to Install CouchDB on Ubuntu 21.04 Linux Operating System

The CouchDB is an open-source database system, managed by the Apache Software Foundation. It is fault-tolerant, and schema-free NoSQL database management system.   CouchDB store data in document or files with JSON data structure. Each document contains fields and...

How to add swap space on Ubuntu 21.04 Operating System

How to add swap space on Ubuntu 21.04 Operating System

The swap space is a unique space on the disk that is used by the system when Physical RAM is full. When a Linux machine runout the RAM it use swap space to move inactive pages from RAM. Swap space can be created into Linux system in two ways, one we can create a...

How to Install Nginx on Ubuntu 21.04 Server

How to Install Nginx on Ubuntu 21.04 Server

Nginx is the most potent, open-source, and a high-performance Web server. It can work as a reverse proxy server also, nowadays, is used by most of the most significant websites on the internet. People pronounced “engine x” for Nginx; it is the hot choice for every...

How to Install VirtualBox on Ubuntu 21.04 Linux

How to Install VirtualBox on Ubuntu 21.04 Linux

VirtualBox is an Open Source tool, known as a cross-platform virtualization application or software. It used to run multiple operating systems or virtual machines simultaneously on a single hardware. In this VirtualBox installation tutorial, we will explain the...

Follow Us

Our Communities

More on Ubuntu

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!



Submit a Comment

Your email address will not be published.

4 + 3 =