FreeBSD 15

Buildah : Scratch から作成する2026/01/09

 

空コンテナーイメージ [scratch] でゼロからコンテナーイメージを作成します。
好み通りにパッケージングしたコンテナーイメージが作成できます。

[1] 例として、FreeBSD 15 イメージを作成します。
# 空コンテナーイメージ [scratch] を作成

root@dlp:~ #
newcontainer=$(buildah from scratch)

root@dlp:~ #
buildah containers

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
ba076e53caa3     *                  scratch                          working-container

# 空コンテナーイメージ [scratch] をマウント

root@dlp:~ #
scratchmnt=$(buildah mount $newcontainer)

root@dlp:~ #
echo $scratchmnt

/var/db/containers/storage/zfs/graph/0697a36687dc49e4a6e4f95f310351a63d97c64684a58deff7b2d290ee3289ea

# ベースシステムをコピー

root@dlp:~ #
fetch https://download.freebsd.org/snapshots/amd64/15.0-STABLE/base.txz

root@dlp:~ #
fetch https://download.freebsd.org/snapshots/amd64/15.0-STABLE/lib32.txz

root@dlp:~ #
tar zxf base.txz -C $scratchmnt

root@dlp:~ #
tar zxf lib32.txz -C $scratchmnt

root@dlp:~ #
buildah umount $newcontainer

ba076e53caa33c5f854e16c4676f31c18b471ba1eb02875fde2200f2c692f817

# ローカルホストにイメージ登録

root@dlp:~ #
buildah commit $newcontainer freebsd-base:latest

Getting image source signatures
Copying blob 6af2ef15f616 done   |
Copying config afb96df720 done   |
Writing manifest to image destination
afb96df7209233bd4baef9e30f3c879cf7eecc3ff9d1aa65e120a3ed455242cd

root@dlp:~ #
buildah images

REPOSITORY               TAG      IMAGE ID       CREATED          SIZE
localhost/freebsd-base   latest   afb96df72092   23 seconds ago   902 MB

root@dlp:~ #
buildah run $newcontainer /bin/echo "Welcome to the Buildah World"

Welcome to the Buildah World
[2] その他、基本的なコンテナーの操作です。
ワーキングコンテナー内へファイルをコピーする。
root@dlp:~ #
container=$(buildah from localhost/freebsd-base:latest)

root@dlp:~ #
echo "buildah test" > buildah.txt

root@dlp:~ #
buildah copy $container buildah.txt /tmp/buildah.txt

d136060fde9746f8d590196421ee63dfc3457cf3817cce9a8f15fa0d34304730
root@dlp:~ #
buildah run $container cat /tmp/buildah.txt

buildah test
[3] ワーキングコンテナーのファイルシステムをマウントする。
root@dlp:~ #
buildah mount $container

/var/db/containers/storage/zfs/graph/4c4ed968795a24e65b366e89484061cb09b0a526f641c4773d5c26ed04897865
root@dlp:~ #
ls -l /var/db/containers/storage/zfs/graph/4c4ed968795a24e65b366e89484061cb09b0a526f641c4773d5c26ed04897865

total 93
-r--r--r--   1 root wheel 6070 Jan  8 12:18 COPYRIGHT
drwxr-xr-x   2 root wheel   49 Jan  8 12:17 bin
drwxr-xr-x  14 root wheel   70 Jan  8 12:18 boot
dr-xr-xr-x   2 root wheel    2 Jan  8 12:17 dev
drwxr-xr-x  30 root wheel  104 Jan  8 12:20 etc
drwxr-xr-x   4 root wheel   80 Jan  8 12:17 lib
drwxr-xr-x   3 root wheel    8 Jan  8 12:17 libexec
drwxr-xr-x   2 root wheel    2 Jan  8 12:17 media
.....
.....

root@dlp:~ #
buildah umount $container

faee608c3e89a61f882197106b8995cd647f4c773a9c354b86bddbae41dc7418
[4] ワーキングコンテナーからカスタムイメージを新規登録する。
root@dlp:~ #
buildah run $container /bin/sh
#
pkg install -y python313

#
exit
root@dlp:~ #
buildah commit $container freebsd-py313:latest

Getting image source signatures
Copying blob 6af2ef15f616 skipped: already exists
Copying blob 28dbc98b5360 done   |
Copying config f81d4e744e done   |
Writing manifest to image destination
f81d4e744ebbe3ce281b7b5386ae1cb049699804072df0f55115066edfbc9c11

root@dlp:~ #
buildah images

REPOSITORY                TAG      IMAGE ID       CREATED          SIZE
localhost/freebsd-py313   latest   f81d4e744ebb   17 seconds ago   1.31 GB
localhost/freebsd-base    latest   afb96df72092   5 minutes ago    902 MB

root@dlp:~ #
buildah run $(buildah from localhost/freebsd-py313) which python3.13

/usr/local/bin/python3.13
関連コンテンツ