目的
Raspberry Pi上で開発をした時に問題となるのはアーキテクチャである。多くのアーキテクチャはamd64やx86アーキテクチャ用にビルドされている。今回はraspberry pi上でamd64やx86アーキテクチャ用にビルドされたイメージを動かす。
確認
まずは、対応しているアーキテクチャの確認
root@shoma:/home/shoma/nagios# docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
default * docker
default default running v0.11.6+0a15675913b7 linux/arm/v8, linux/arm64
構築
qemuをインストールする事によって、対応するアーキテクチャを増やそう
apt install -y qemu-user-static
確認
root@shoma:/home/shoma/nagios# docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
default * docker
default default running v0.11.6+0a15675913b7 linux/arm/v8, linux/arm64, linux/amd64, linux/riscv64, linux/ppc64, linux/ppc64le, linux/s390x, linux/386
ビルド
root@shoma:/home/shoma/nagios# docker run --rm --platform=linux/amd64 ubuntu uname -a
確認
root@shoma:/home/shoma/nagios# docker inspect --format='{{.Architecture}}' ubuntu
amd64
例
今回はnagiosのイメージをraspberrypi上で動作させる。
Dockerfileの作成
FROM jasonrivers/nagios
通常時
通常だとこの様になる
Attaching to nagios4
nagios4 | exec /usr/local/bin/start_nagios: exec format error
nagios4 exited with code 1
buildx使用
docker buildx create --use
docker buildx use default
docker buildx build . --platform linux/amd64,linux/arm64 -t shomaigu/nagios --push
docker-compose.yml
version: '3.3'
services:
nagios:
container_name: nagios4
volumes:
- '/opt/nagios/etc/:/opt/nagios/etc/'
ports:
- '7070:80'
image: shomaigu/nagios:latest
確認
起動した!
root@shoma:/home/shoma/nagios# docker-compose up
Removing nagios4 ... done
Removing network nagios_default
Creating network "nagios_default" with the default driver
Pulling nagios (shomaigu/nagios:latest)...
latest: Pulling from shomaigu/nagios
eaead16dc43b: Already exists
4bae43e3fd96: Already exists
52ad2fe8213e: Already exists
1fefd86dc30b: Already exists
c76d27f07a58: Already exists
387ce09ce1ab: Already exists
22caebe519a4: Already exists
284d8ff98a86: Already exists
5911ed644fcf: Already exists
ad9935e81d55: Already exists
d0cf54fef9ee: Already exists
2f6624440634: Already exists
f37caf0d4870: Already exists
a966221e8b70: Already exists
31802b0ce331: Already exists
e917ce7af6a7: Already exists
18cfd2a63e67: Already exists
6feb61860fe4: Already exists
11c8bc88c0ae: Already exists
a0103bd2a865: Already exists
e81a2936f284: Already exists
6dc656771756: Already exists
affcdbc9e52e: Already exists
9ddbc33d3367: Already exists
326b67785868: Already exists
a4a580e2dae3: Already exists
1615f8c2703f: Already exists
451eeae1894f: Already exists
5dd09c4cc887: Already exists
f4360ee2b67e: Already exists
Digest: sha256:4ba875f0b50a341e589802e215ac4730de73b258411cd64ae4522653cd5f5a86
Status: Downloaded newer image for shomaigu/nagios:latest
Creating nagios4 ... done
Attaching to nagios4
nagios4 | Started with empty ETC, copying example data in-place
nagios4 | Adding password for user nagiosadmin
nagios4 | Started runsvdir, PID is 24
nagios4 | checking permissions for nagios & nagiosgraph
nagios4 | rsyslogd: [origin software="rsyslogd" swVersion="8.2001.0" x-pid="45" x-info="https://www.rsyslog.com"] start
nagios4 | nagios: Nagios 4.4.8 starting... (PID=43)
nagios4 | nagios: Local time is Mon Aug 28 14:58:11 UTC 2023
nagios4 | nagios: LOG VERSION: 2.0
nagios4 |
nagios4 | Nagios Core 4.4.8
nagios4 | Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
nagios4 | Copyright (c) 1999-2009 Ethan Galstad
nagios4 | Last Modified: 2022-10-04
nagios4 | License: GPL
nagios4 |
nagios4 | Website: https://www.nagios.org
nagios4 | Nagios 4.4.8 starting... (PID=43)
nagios4 | Local time is Mon Aug 28 14:58:11 UTC 2023
nagios4 | nagios: qh: Socket '/opt/nagios/var/rw/nagios.qh' successfully initialized
nagios4 | nagios: qh: core query handler registered
nagios4 | nagios: qh: echo service query handler registered
nagios4 | nagios: qh: help for the query handler registered
nagios4 | wproc: Successfully registered manager as @wproc with query handler
nagios4 | nagios: wproc: Successfully registered manager as @wproc with query handler
nagios4 | wproc: Registry request: name=Core Worker 88;pid=88
nagios4 | nagios: wproc: Registry request: name=Core Worker 88;pid=88
nagios4 | wproc: Registry request: name=Core Worker 84;pid=84
nagios4 | nagios: wproc: Registry request: name=Core Worker 84;pid=84
nagios4 | wproc: Registry request: name=Core Worker 87;pid=87
nagios4 | nagios: wproc: Registry request: name=Core Worker 87;pid=87
nagios4 | wproc: Registry request: name=Core Worker 91;pid=91
nagios4 | nagios: wproc: Registry request: name=Core Worker 91;pid=91
nagios4 | wproc: Registry request: name=Core Worker 89;pid=89
nagios4 | nagios: wproc: Registry request: name=Core Worker 89;pid=89
nagios4 | wproc: Registry request: name=Core Worker 86;pid=86
nagios4 | nagios: wproc: Registry request: name=Core Worker 86;pid=86
nagios4 | nagios: Successfully launched command file worker with pid 113
nagios4 | Successfully launched command file worker with pid 113
nagios4 | postfix/master[53]: daemon started -- version 3.4.13, configuration /etc/postfix