Akercode.com

How To Install Docker on Ubuntu 20.04

This How-To will describe how to install Docker on Ubuntu 20.04.

Install Docker

Uninstall old versions:

sudo apt-get remove docker docker-engine docker.io containerd runc

Setup the repository:

sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

Add Docker’s official GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Use the following command to set up the stable repository:

echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker Engine:

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

Run Docker Commands Without Sudo

Add current user ${USER} to the docker group:

sudo usermod -aG docker ${USER}

Log out of the server and back in, or just change user for the changes to take effect:

su - ${USER}

To see which users is currently in the docker group, type:

id -nG

Output:

aker sudo docker

Check installed version:

docker version --format '{{.Server.Version}}'

Output:

20.10.7

(Optional) Verify that Docker Engine is installed correctly by running the hello-world image:

docker run hello-world