How to install docker 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.

There are two versions of Docker – Docker CE (Community Edition) and Docker EE (Enterprise Edition). If you have a small-scale project, or you’re just learning, you will want to use Docker CE.

In this post covers how to install Docker on an Ubuntu 20.04.

First, update the packages index and install the dependencies necessary:

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

Import the repository’s GPG key using the following curl command:

$ curl -fsSL | sudo apt-key add -

Add the Docker APT repository to your system:

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

Second, install docker with latest version:

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

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

$ sudo systemctl status docker

Executing Docker Commands as a Non-Root User

$ sudo usermod -aG docker $USER

Verifying the Installation

$ 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

That’s it.
Enjoy your docker!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s