Debian 13 trixie

Buildah : インストール2025/08/22

 

コンテナーイメージ作成ツール Buildah をインストールします。

OCI (Open Container Initiative) イメージ フォーマットに準拠したコンテナーイメージを作成可能 且つ デーモン不要で利用できます。

[1] Buildah をインストールします。
root@dlp:~#
apt -y install buildah
[2] Buildah の基本操作です。
イメージからワーキングコンテナーを新規作成する。
# [debian] イメージからワーキングコンテナー作成

root@dlp:~#
buildah from debian

debian-working-container

# コンテナーリスト

root@dlp:~#
buildah containers

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
e9f9b36a6e56     *     047bd8d81940 docker.io/library/debian:latest  debian-working-container

# コンテナーイメージリスト

root@dlp:~#
buildah images

REPOSITORY                 TAG      IMAGE ID       CREATED       SIZE
docker.io/library/debian   latest   047bd8d81940   11 days ago   124 MB

# コンテナーイメージは podman からも使用可

root@dlp:~#
podman images

REPOSITORY                TAG         IMAGE ID      CREATED      SIZE
docker.io/library/debian  latest      047bd8d81940  11 days ago  124 MB
[3] ワーキングコンテナーを操作する。
# シェル変数に格納可能

root@dlp:~#
container=$(buildah from debian)

root@dlp:~#
echo $container

debian-working-container-1
# コンテナーから各種コマンド実行可能

root@dlp:~#
buildah run $container echo "Hello Buildah World"

Hello Buildah World
root@dlp:~#
buildah run $container bash

root@b1bd18cfd87d:/#
apt-get update; apt-get -y install python3

root@b1bd18cfd87d:/#
root@dlp:~#
buildah run $container whereis python3

python3: /usr/bin/python3 /usr/lib/python3 /etc/python3 /usr/share/python3 /usr/share/man/man1/python3.1.gz
[4] ワーキングコンテナー内へファイルをコピーする。
root@dlp:~#
echo "buildah test" > buildah.txt

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

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

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

/var/lib/containers/storage/overlay/3f24c40e0bba1980735d64d5a5027fc578781927667af8a3bc4f25e733dbca5e/merged
root@dlp:~#
ll /var/lib/containers/storage/overlay/3f24c40e0bba1980735d64d5a5027fc578781927667af8a3bc4f25e733dbca5e/merged

total 68
lrwxrwxrwx 1 root root    7 May 13 04:25 bin -> usr/bin
drwxr-xr-x 2 root root 4096 May 13 04:25 boot
drwxr-xr-x 2 root root 4096 Aug 11 09:00 dev
drwxr-xr-x 1 root root 4096 Aug 22 10:47 etc
drwxr-xr-x 2 root root 4096 May 13 04:25 home
.....
.....

# アンマウント

root@dlp:~#
buildah umount $container

b1bd18cfd87d520b7cd0072967ee662b2a2428afcedafecd60627292700d08df
[6] ワーキングコンテナーからイメージを作成する。
root@dlp:~#
buildah commit $container my-debian:latest

Getting image source signatures
Copying blob cb9eb84282d0 skipped: already exists
Copying blob d9286a001850 done   |
Copying config 77fd1e5643 done   |
Writing manifest to image destination
77fd1e5643fd483119cecff368302e96bb85e265806741ea15a17cb6ff227938

root@dlp:~#
buildah images

REPOSITORY                 TAG      IMAGE ID       CREATED          SIZE
localhost/my-debian        latest   77fd1e5643fd   16 seconds ago   187 MB
docker.io/library/debian   latest   047bd8d81940   11 days ago      124 MB

# 作成したコンテナーイメージは podman からも利用可

root@dlp:~#
podman run localhost/my-debian hostname

0641e41ad3c1
[7] コンテナーイメージを指定の Registry へ Push する。
root@dlp:~#
buildah images

REPOSITORY                 TAG      IMAGE ID       CREATED          SIZE
localhost/my-debian        latest   77fd1e5643fd   58 seconds ago   187 MB
docker.io/library/debian   latest   047bd8d81940   11 days ago      124 MB

# [localhost/my-debian] イメージを [node01.srv.world:5000] へ Push する
# Push 先の registry が SSL/TLS 未対応の場合は [--tls-verify=false] オプション付加が必要

root@dlp:~#
buildah push --tls-verify=false localhost/my-debian node01.srv.world:5000/my-debian
root@dlp:~#
curl node01.srv.world:5000/v2/_catalog

{"repositories":["my-debian"]}
# 他の任意のノードから Pull 可能

root@node01:~#
podman pull --tls-verify=false node01.srv.world:5000/my-debian

root@node01:~#
podman images

REPOSITORY                    TAG         IMAGE ID      CREATED        SIZE
dlp.srv.world:5000/my-debian  latest      77fd1e5643fd  2 minutes ago  187 MB
localhost/my-debian           latest      77fd1e5643fd  2 minutes ago  187 MB
docker.io/library/debian      latest      047bd8d81940  11 days ago    124 MB
関連コンテンツ