2026-03-27

【Strapi on Raspberry Pi】Raspberry Pi セットアップ (4)

 Herokuで動かしているStrapiをRaspberry Piに移行するプロジェクト。
 前回 → 【Strapi on Raspberry Pi】Raspberry Pi Imager で OS を焼く (3)

起動

 Raspberry Piに電源を繋ぎ起動する。

% ssh -i ~/.ssh/xxx {user name}@{host name}.local
Welcome to Ubuntu 24.04.4 LTS (GNU/Linux 6.8.0-1048-raspi aarch64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

 System information as of Wed Mar 18 20:17:33 JST 2026

  System load:            0.37
  Usage of /:             1.1% of 228.67GB
  Memory usage:           2%
  Swap usage:             0%
  Temperature:            59.0 C
  Processes:              148
  Users logged in:        0
  IPv4 address for wlan0: ***.***.***.***
  IPv6 address for wlan0: ****:****:****:****:****:****:****:****


Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


Last login: Wed Mar 18 20:00:14 2026 from ****:****:****:****:****:****:****:****

 sshでログイン。Imagerで入力したホスト名に.localをつけることで接続先ドメイン名として利用できる。
 温度もわかるんやね。

動作確認

 さて、動作確認を行う。

$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0    7:0    0  41.6M  1 loop /snap/snapd/25939
loop1    7:1    0  41.8M  1 loop /snap/snapd/26383
sda      8:0    0 232.9G  0 disk
├─sda1   8:1    0   512M  0 part /boot/firmware
└─sda2   8:2    0 232.4G  0 part /

 sda1がブートパーティション、sda2がルートパーティションとして正しくパーティションされている。


$ sudo apt update
   sudo apt upgrade -y
   sudo reboot
Hit:1 http://ports.ubuntu.com/ubuntu-ports noble InRelease
Hit:2 http://ports.ubuntu.com/ubuntu-ports noble-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
42 packages can be upgraded. Run 'apt list --upgradable' to see them.
...

 パッケージのアップデートも行う。


$ timedatectl
               Local time: Wed 2026-03-18 20:31:33 JST
           Universal time: Wed 2026-03-18 11:31:33 UTC
                 RTC time: Wed 2026-03-18 11:31:33
                Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

 タイムゾーンも日本になっていることを確認。


$ free -h
               total        used        free      shared  buff/cache   available
Mem:           7.8Gi       328Mi       7.3Gi       3.3Mi       331Mi       7.4Gi
Swap:             0B          0B          0B

 メモリの状態に異常がないことを確認。


$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.4 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

 OSもちゃんとUbuntuがインストールされている。


$ df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           794M  3.4M  791M   1% /run
/dev/sda2       229G  2.5G  217G   2% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
/dev/sda1       505M  187M  318M  38% /boot/firmware
tmpfs           794M   12K  794M   1% /run/user/1000

 ディスクの空き容量を確認。ストレージも十分だ。


$ ping -c 3 google.com
PING google.com (2404:6800:4004:807::200e) 56 data bytes
64 bytes from nrt12s15-in-x0e.1e100.net (2404:6800:4004:807::200e): icmp_seq=1 ttl=115 time=4.50 ms
64 bytes from nrt12s15-in-x0e.1e100.net (2404:6800:4004:807::200e): icmp_seq=2 ttl=115 time=4.58 ms
64 bytes from nrt12s15-in-x0e.1e100.net (2404:6800:4004:807::200e): icmp_seq=3 ttl=115 time=7.23 ms

--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms

 疎通も確認しておこう。

Dockerインストール

最初に述べたように、StrapiやDBはDockerで動かす。

 上記を参考に、Dockerをサーバにインストールする。

手順通りにコマンドを実行する
$ which docker
$ echo $?
1

$ sudo apt install ca-certificates curl
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
ca-certificates is already the newest version (20240203).
ca-certificates set to manually installed.
curl is already the newest version (8.5.0-2ubuntu10.8).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

$ sudo install -m 0755 -d /etc/apt/keyrings
$ echo $?
0

$ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
$ echo $?
0

$ sudo chmod a+r /etc/apt/keyrings/docker.asc
$ echo $?
0

$ sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: noble
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc

$ sudo apt update
Get:1 https://download.docker.com/linux/ubuntu noble InRelease [48.5 kB]
Get:2 https://download.docker.com/linux/ubuntu noble/stable arm64 Packages [46.6 kB]
Hit:3 http://ports.ubuntu.com/ubuntu-ports noble InRelease
Hit:4 http://ports.ubuntu.com/ubuntu-ports noble-security InRelease
Fetched 95.1 kB in 1s (72.5 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

$ sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  docker-ce-rootless-extras libslirp0 pigz slirp4netns
Suggested packages:
  cgroupfs-mount | cgroup-lite docker-model-plugin
The following NEW packages will be installed:
  containerd.io docker-buildx-plugin docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin libslirp0 pigz slirp4netns
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 84.3 MB of archives.
After this operation, 371 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 https://download.docker.com/linux/ubuntu noble/stable arm64 containerd.io arm64 2.2.2-1~ubuntu.24.04~noble [20.2 MB]

...

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled)
     Active: active (running) since Wed 2026-03-18 20:37:43 JST; 27s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 1826 (dockerd)
      Tasks: 10
     Memory: 28.1M (peak: 29.0M)
        CPU: 464ms
     CGroup: /system.slice/docker.service
             └─1826 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Mar 18 20:37:43 ******* dockerd[1826]: time="2026-03-18T20:37:43.112383007+09:00" level=info msg="Restoring containers: start."
Mar 18 20:37:43 ******* dockerd[1826]: time="2026-03-18T20:37:43.148563708+09:00" level=info msg="Deleting nftables IPv4 rules" error="exit status 1" output="Error: Could not process rule: No such file or directory
delete table ip docker-bridges"
Mar 18 20:37:43 ******* dockerd[1826]: time="2026-03-18T20:37:43.161493371+09:00" level=info msg="Deleting nftables IPv6 rules" error="exit status 1" output="Error: Could not process rule: No such file or directory
delete table ip6 docker-bridges"
Mar 18 20:37:43 ******* dockerd[1826]: time="2026-03-18T20:37:43.533555754+09:00" level=info msg="Loading containers: done."
Mar 18 20:37:43 ******* dockerd[1826]: time="2026-03-18T20:37:43.547388859+09:00" level=info msg="Docker daemon" commit=83bca51 containerd-snapshotter=true storage-driver=overlayfs version=29.3.0
Mar 18 20:37:43 ******* dockerd[1826]: time="2026-03-18T20:37:43.547621302+09:00" level=info msg="Initializing buildkit"
Mar 18 20:37:43 ******* dockerd[1826]: time="2026-03-18T20:37:43.591765070+09:00" level=info msg="Completed buildkit initialization"
Mar 18 20:37:43 ******* dockerd[1826]: time="2026-03-18T20:37:43.599676027+09:00" level=info msg="Daemon has completed initialization"
Mar 18 20:37:43 ******* dockerd[1826]: time="2026-03-18T20:37:43.599833323+09:00" level=info msg="API listen on /run/docker.sock"
Mar 18 20:37:43 ******* systemd[1]: Started docker.service - Docker Application Container Engine.

 Dockerのインストールが完了したので、実際にDockerコンテナを起動してみる。

$ docker run hello-world
permission denied while trying to connect to the docker API at unix:///var/run/docker.sock

 しかし、sudoをつけないとdockerコマンドを実行できないので

$ sudo usermod -aG docker $USER

 実行ユーザをdockerグループに所属させ、sudoなしでdockerコマンドを実行できるようにする。

$ exit
logout
Connection to ******* closed.

% ssh -i ~/.ssh/xxx {user name}@{host name}.local
Welcome to Ubuntu 24.04.4 LTS (GNU/Linux 6.8.0-1048-raspi aarch64)

$ docker run --rm hello-world

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/

 ログインし直して、再度sudoなしでdockerを起動。



 ラズパイも問題なく起動できた。次はDBのセットアップを行う。