みつきんのメモ

組み込みエンジニアです。Interface誌で「Yocto Projectではじめる 組み込みLinux開発入門」連載中

YoctoProject ラズパイ4でdocker

はじめに

筆者がDEBIXでぐずぐずやっている間にTLに下記のようなものが流れてきた。

このお方は必要であれば放っておいても自力でどうにかされるのだが、いいお題なので試してみる。

meta-virtualization

xenやらlxcやら仮想化の機能を詰め込んだレイヤがmeta-virtualizationである。もちろんこの中にdocker-ceも含まれている。 これは基本的にBSP層は関係ないので持ってきたら動かせるはず。

ただし、カーネルの機能には依存しているので、プラットフォームによってはコンフィグなどは調整する必要があるかもしれない。

とりあえず、今回はラズベリーパイ4を使用してdockerを動かしてみる。 YoctoProjectのブランチはkirkstoneを使用する。

環境構築

作業環境

$ mkdir -p ~/yocto/rpi-kirkstone
$ cd ~/yocto/rpi-kirkstone

pokyの取得

$ git clone git://git.yoctoproject.org/poky.git -b kirkstone 

環境変数の設定

$ source poky/oe-init-build-env

meta-raspberrypiの取得

$ bitbake-layers layerindex-fetch meta-raspberrypi

meta-virtualization

dockerを使用するためにmeta-virtualizationを取得しビルド対象に含める。依存する他のレイヤも一緒に引っ張ってくる。

$ bitbake-layers layerindex-fetch meta-virtualization meta-python meta-networking meta-filesystems meta-oe

local.confを編集

MACHINE = "raspberrypi4-64"
DL_DIR = "${TOPDIR}/../downloads"

# systemd
DISTRO_FEATURES:append = " systemd pam"
VIRTUAL-RUNTIME_init_manager = "systemd"
DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
VIRTUAL-RUNTIME_initscripts = ""

# enable uart
ENABLE_UART = "1"

# docker
IMAGE_INSTALL:append = " packagegroup-docker"

ビルド

$ bitbake core-image-base

動作確認

ターゲットはLANか無線LANでインターネットにアクセスできるようにしておく。

シリアルコンソールで実行するとカーネルログもうじゃうじゃ出るが、「Hello from Docker! This message shows that your installation appears to be working correctly.」もきちんと出力されている。

root@raspberrypi4-64:~# docker run hello-world
[30139.948961] docker0: port 1(veth1cf1ac9) entered blocking state
[30139.955135] docker0: port 1(veth1cf1ac9) entered disabled state
[30139.962038] device veth1cf1ac9 entered promiscuous mode
[30139.967491] audit: type=1700 audit(1677102815.507:54): dev=veth1cf1ac9 prom=256 old_prom=0 auid=4294967295 uid=0 gid=0 ses=4294967295
[30139.979792] audit: type=1300 audit(1677102815.507:54): arch=c00000b7 syscall=206 success=yes exit=40 a0=f a1=4000e7d0e0 a2=28 a3=0 items=0 ppid=1 pid=366 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsu)
[30140.010097] audit: type=1327 audit(1677102815.507:54): proctitle=2F7573722F62696E2F646F636B657264002D480066643A2F2F
[30140.896771] eth0: renamed from veth8fd4f92
[30140.935651] IPv6: ADDRCONF(NETDEV_CHANGE): veth1cf1ac9: link becomes ready
[30140.942952] docker0: port 1(veth1cf1ac9) entered blocking state
[30140.949006] docker0: port 1(veth1cf1ac9) entered forwarding state

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/

[30141.280346] docker0: port 1(veth1cf1ac9) entered disabled state
[30141.286936] veth8fd4f92: renamed from eth0
[30141.367995] docker0: port 1(veth1cf1ac9) entered disabled state
[30141.378777] device veth1cf1ac9 left promiscuous mode
[30141.383899] docker0: port 1(veth1cf1ac9) entered disabled state
[30141.383960] audit: type=1700 audit(1677102816.923:55): dev=veth1cf1ac9 prom=0 old_prom=256 auid=4294967295 uid=0 gid=0 ses=4294967295
[30141.426246] audit: type=1300 audit(1677102816.923:55): arch=c00000b7 syscall=206 success=yes exit=32 a0=f a1=40003c5020 a2=20 a3=0 items=0 ppid=1 pid=366 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsu)
[30141.453833] audit: type=1327 audit(1677102816.923:55): proctitle=2F7573722F62696E2F646F636B657264002D480066643A2F2F
root@raspberrypi4-64:~#

まとめ

YoctoProject環境でもdockerは動く。