How to install Docker on Ubuntu 20.04

s2 0

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 contains everything the software needs to run.

Docker is an integral part of modern software development and DevOps continuous integration and deployment pipelines.

This tutorial will show you how to install Docker on an Ubuntu 20.04 computer.

Docker is available to install from the standard Ubuntu 20.04 repositories, but it may not always be the latest version. We install the latest Docker package from the official Docker repositories.

Install Docker on Ubuntu 20.04

Installing Docker on Ubuntu is pretty straightforward. We activate the Docker repository, import the repository GPG key and install the package.

First, update the package index and install the dependencies required to add a new HTTPS repository:

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

Import the repository’s GPG key as follows: curl
Command:

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

Add the Docker APT repository to your system:

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

Now that the Docker repository is activated, you can install any version of Docker that is available in the repositories.

  1. Run the following commands to install the latest version of Docker. If you want to install a specific version of Docker, skip this step and move on to the next.

    sudo apt updatesudo apt install docker-ce docker-ce-cli containerd.io
  2. To install a specific version, first list all available versions in the Docker repository:

    sudo apt updateapt list -a docker-ce

    The available Docker versions are shown in the second column. At the time of this writing, there is only one Docker version (5:19.03.9~3-0~ubuntu-focal) available in the official Docker repositories.

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

    Install a specific version by adding it =<VERSION> after the package name:

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

Once the installation is complete, the Docker service will start automatically. You can check it out by typing:

sudo systemctl status docker

The output looks 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 with the default sudo apt update && sudo apt upgrade Procedure.

If you want to prevent the Docker package from being updated, mark it as on hold:

sudo apt-mark hold docker-ce

Run Docker commands as a non-root user

By default, only root and users with sudo privileges can run Docker commands.

To run Docker commands as a non-root user, you need to add your user to the Docker group that is created during the Docker CE package installation. To do this, enter the following:

sudo usermod -aG docker $USER

$USER is an environment variable that contains your username.

Sign out and sign back in to update group membership.

Check the installation

To verify that Docker installed successfully and that you can run the command docker Command without prefix sudo
, let’s run a test container:

docker container run hello-world

The command downloads the test image if it is not found locally, runs it in a container, prints a “Hello from Docker” message, and exits. The output should look like this:

The container is paused after the message is printed because it does not have a long-running process.

By default, Docker pulls images from the Docker Hub. It is a cloud-based registration service that, among other things, stores the Docker images in public or private repositories.

Uninstall Docker

Before uninstalling Docker, you should remove all containers, images, volumes, and networks.

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 like any other package that was installed with it apt:

sudo apt purge docker-cesudo apt autoremove

diploma

We showed you how to install Docker on an Ubuntu 20.04 computer. To learn more about Docker, visit the official Docker documentation
.

If you have any questions please leave a comment below.