Prerequisites

In order to install  Docker, you will need to have sudo rights on your host. If you are not sure about it, run the following command

$ sudo -v

update your existing list of packages:

  • sudo apt update
 


Installing docker-ce packages 

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 for ARM64 architecture, the assumption here is that you are using the Ubuntu 20.04 i.e. Ubuntu focal distribution:

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

Next, update the package database with the Docker packages from the newly added repo:

  • sudo apt update
 

Make sure you are about to install from the Docker repo instead of the default Ubuntu repo:

  • apt-cache policy docker-ce
 

You’ll see output like this, although the version number for Docker may be different: Output of apt-cache policy docker-ce


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

 

Notice that docker-ce is not installed, but the candidate for installation is from the Docker repository for Ubuntu 20.04 (focal). 

Finally, install Docker:

  • sudo apt install docker-ce
 

Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running:

  • sudo systemctl status docker
 

The output should be similar to the following, showing that the service is active and running:

Output
● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2021-03-04 18:44:58 UTC; 14h ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 16213 (dockerd) Tasks: 38 Memory: 209.6M CGroup: /system.slice/docker.service ├─16213 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock └─17526 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8080 -container-ip 172.17.0.2 -container-port 80

Installing Docker gives you not just the Docker service (daemon) but also the docker command line utility, or the Docker client. 


To ensure that docker deamon starts at boot :

  • sudo systemctl enable docker
 


Verifying docker installation


By default, the docker command can only be run the root user or by a user in the docker group, which is automatically created during Docker’s installation process. If you attempt to run the docker command without prefixing it with sudo or without being in the docker group, you’ll get an output like this:

Output
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?. See 'docker run --help'.

If you want to avoid typing sudo whenever you run the docker command, add your username to the docker group:

  • sudo usermod -aG docker ${USER}
 

To apply the new group membership,  log out of the server and back in, or type the following:

  • su - ${USER}
 

You will be prompted to enter your user’s password to continue.  

Confirm that your user is now added to the docker group by typing:

  • id -nG
 
Output
sammy sudo docker

If you need to add a user to the docker group that you’re not logged in as, declare that username explicitly using:

  • sudo usermod -aG docker username
 

We are now equipped to run docker commands and we will verify our installation with a classic hello-world

  • docker run hello-world


You should see output similar to the following, verifying that the installed docker container platform is opperational:

Output
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 256ab8fe8778: Already exists Digest: sha256:7e02330c713f93b1d3e4c5003350d0dbe215ca269dd1d84a4abc577908344b30 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (arm64v8) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/