Setup Docker on Ubuntu 20 VM

In this article we will explore how to install and use docker on Ubuntu 20.04.2. In context of this article we will use Ubuntu 20 VM running on VMWare ESXi, however instructions provided in this article are valid for any standalone / vm deployment of Ubuntu linux server.

We will use official docker repository instead of ubuntu official repository, this will ensure installation of latest Docker version.

First we will update list of apt packages.

sudo apt update

We will install apt-transport-https and ca-certificates packages to enable apt work with HTTPS transport.

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

Execute following command to add GPG key of the docker repository.

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

Now we will docker repository to apt sources.

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

Update the apt package list again.

sudo apt update

Execute following command to make sure apt installs docker from docker instead of ubuntu repository.

apt-cache policy docker-ce

Here is the output of apt-cache command.

docker-ce:
  Installed: (none)
  Candidate: 5:20.10.4~3-0~ubuntu-focal
  Version table:
     5:20.10.4~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.3~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.2~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.1~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.0~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.15~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.14~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.13~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.12~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.11~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.10~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.9~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages

Install docker using apt install command as following.

sudo apt install docker-ce

Run following command to check current status of docker service.

sudo service docker status

Following output shows docker service is running and active.

 docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2021-03-01 22:15:55 UTC; 27s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 5367 (dockerd)
      Tasks: 8
     Memory: 39.8M
     CGroup: /system.slice/docker.service
             └─5367 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

You can use following commands to stop, start and restart docker service.

sudo service docker stop
sudo service docker start
sudo service docker restart

Our docker installation is complete and ready to use now, however we will have to use sudo to run docker commands. Following steps in this article will help us avoid typing sudo with docker command.

Add your current user to docker group, do not forget to replace user_name with your ubuntu user name.

sudo usermod -aG docker user_name

Logout and login again using following command to apply changes in group membership.

su - user_name

To confirm if your user has been added to docker group, run following command.

id -nG

This will list the name groups current user is member of.

sma adm cdrom sudo dip plugdev lxd docker

Thanks for reading.

Shoket Mahmood Ahmed

Leave a Reply

Back to top