Install Docker Engine on Ubuntu 20.04
Install Docker Engine on Ubuntu 20.04

Docker is an open-source containerization platform that allows you to quickly build, test, and deploy applications as portable containers that can run virtually anywhere. A container represents a runtime for a single application and includes everything the software needs to run.

First, update your existing list of packages:

sudo apt update

Next, install a few prerequisite packages which let apt use packages over HTTPS:

sudo apt install apt-transport-https ca-certificates curl software-properties-common

Then add the GPG key for the official Docker repository to your system:

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

Add the Docker repository to APT sources:

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

Next, update the package database with the Docker packages from the newly added repo and install the docker

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

Once the installation is completed, the Docker service will start automatically. You can verify it by typing

sudo systemctl status docker

The output will look something like this

● 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 is released, you can update the packages using the standard sudo apt update && sudo apt upgrade procedure.

Executing Docker Commands as a Non-Root User

By default, only root and user with sudo privileges can execute Docker commands.

To execute Docker commands as non-root user you’ll need to add your user to the docker group that is created during the installation of the Docker CE package. To do that, type in:

sudo usermod -aG docker $USER

$USER is an environment variable holds your username.

Verifying the Installation

To verify that Docker has been successfully installed and that you can execute the docker command

docker container run hello-world

The command will download the test image, if not found locally, run it in a container, print a “Hello from Docker” message, and exit.

Uninstalling Docker 

Run the following commands to stop all running containers and remove all docker objects:

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

You can now uninstall Docker as any other package installed with apt:

sudo apt purge docker-ce
sudo apt autoremove

We’ve shown you how to install Docker on Ubuntu 20.04 machine. To learn more about Docker, check out the official Docker documentation .