In this post, we will learn how to install Docker in a raspberry pi 4. Docker is the de facto standard to make containerized apps.

I need a way to practice and make further laboratories, and the best way to encapsulate the environment is with Docker.

Requirements

  • Raspberry pi 4 with Ubuntu 20.04.1 LTS image
  • Basic Linux commands
  • Basic understanding of Docker

Hands-on

  1. Uninstall any older version of docker

This will preserve the content on /var/lib/docker/ images, containers, volumes, and networks of any older version.

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

2. Install dependencies needed by docker.

sudo apt update && sudo apt install -y \
apt-transport-https ca-certificates curl \
gnupg-agent software-properties-common

3. Add Docker’s official GPG key:

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

4. Set up the stable repository of Docker in our computer

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

5. Update and install docker

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

6. Test the binary with docker version

sudo docker version
Client: Docker Engine - Community
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46
 Built:             Wed Sep 16 17:03:40 2020
 OS/Arch:           linux/arm64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.13
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       4484c46
  Built:            Wed Sep 16 17:02:11 2020
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.3.7
  GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
If you try to use docker version with the actual user (without sudo) you will get an error like this
docker version
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46
 Built:             Wed Sep 16 17:03:40 2020
 OS/Arch:           linux/arm64
 Experimental:      false
Got permission denied while trying to connect to the Docker daemon socket at
unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/version:
dial unix /var/run/docker.sock: connect: permission denied Client: Docker Engine - Community

This is because you need to add the current user to the docker group

7. Add the user to the docker group

sudo usermod -aG docker $USER
$USER is a environment variable that will echo your current username.

8. Apply the changes to the group, you can restart the terminal, or you can use the newgrp command

newgrp docker
You can also logout and login in the terminal

9. Test the installation with "docker version"

docker version
Client: Docker Engine - Community
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46
 Built:             Wed Sep 16 17:03:40 2020
 OS/Arch:           linux/arm64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.13
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       4484c46
  Built:            Wed Sep 16 17:02:11 2020
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.3.7
  GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Well done, Docker installed and working.

References: