[Raspberry Pi 4] Install Docker on the 64-bit Version of Raspberry Pi OS

Docker

This is a memo. It is the same procedure as installing on Ubuntu. The repository URL is about the only difference.

Test Environment

Raspberry Pi 4, 8GB memory
*On this site, I use a SanDisk SSD and a Buffalo SSD for storage. (Reference: [Raspberry Pi 4] Change the Pi 4 Storage from an SD Card to an SSD)

I use the 64-bit version of Raspberry Pi OS.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

Install Docker

# 旧バージョン等のクリーンアップ
$ sudo apt-get remove docker docker-engine docker.io containerd runc
# Set up the repository
$ sudo apt-get update

パッケージのインストール。libffi-devは docker-compose を入れるときに必要

$ sudo apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release libffi-dev

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

set up the stable repository for arm64

$ echo “deb [arch=arm64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian
$(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 -y docker-ce docker-ce-cli containerd.io

# Docker-compose のインストール
$ sudo apt install -y python3-pip
$ sudo pip3 install docker-compose

# バージョンの確認
$ docker --version
Docker version 20.10.8, build 3967b7d
$ docker-compose --version
docker-compose version 1.29.2, build unknown

Try Running the Hello World Image

# Verify that Docker Engine is installed correctly by running the hello-world image.
$ sudo docker run hello-world

piユーザーでも sudo なしで dockerコマンドを扱えるようにしておく。

$ sudo usermod -a -G docker pi

Bonus

I wrote the sequence of installation-related commands in a gist.
If you do not want to run each command manually, the following command runs the full set.
*This is amateur work, so use it at your own risk.

$ curl -sf https://gist.githubusercontent.com/hagewashi/0bcd8c0ed5149fe99a85a0a4896bd4cd/raw/b1aa2633ebec05dba9baf0a41cab99c6a63ffce4/RaspberryPiOS_docker_install.sh | sudo sh -s
Me
Me

This is just an operation log.