Ubuntu 26.04

Buildah : インストール2026/05/06

 

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

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

[1]

UFW を有効にしている場合は、こちらの [1] を参考に Forward ポリシーを有効にしておきます。

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

root@dlp:~#
buildah from ubuntu

Resolved "ubuntu" as an alias (/etc/containers/registries.conf.d/shortnames.conf)
Trying to pull docker.io/library/ubuntu:latest...
Getting image source signatures
Copying blob 1c24335ddd46 done   |
Copying blob 6f5c5aa4e145 done   |
Copying config 30ba44506a done   |
Writing manifest to image destination
ubuntu-working-container

# コンテナーリスト

root@dlp:~#
buildah containers

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
e7a8eafbd218     *     30ba44506a6d docker.io/library/ubuntu:latest  ubuntu-working-container

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

root@dlp:~#
buildah images

REPOSITORY                 TAG      IMAGE ID       CREATED       SIZE
docker.io/library/ubuntu   latest   30ba44506a6d   2 weeks ago   111 MB

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

root@dlp:~#
podman images

REPOSITORY                TAG         IMAGE ID      CREATED      SIZE
docker.io/library/ubuntu  latest      30ba44506a6d  2 weeks ago  111 MB
[4] ワーキングコンテナーを操作する。
# シェル変数に格納可能

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

root@dlp:~#
echo $container

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

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

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

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

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

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

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

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

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

/var/lib/containers/storage/overlay/64b4f5d3367a4d4d78cbd2895e0ffbad3ac2f9e0b56880eb79e2a2c151c8ea97/merged
root@dlp:~#
ll /var/lib/containers/storage/overlay/64b4f5d3367a4d4d78cbd2895e0ffbad3ac2f9e0b56880eb79e2a2c151c8ea97/merged

total 80
dr-xr-xr-x 1 root root 4096 May  6 01:06 ./
drwx------ 5 root root 4096 May  6 01:08 ../
drwxr-xr-x 2 root root 4096 Apr 21 17:23 .rock/
lrwxrwxrwx 1 root root    7 Apr 20 08:46 bin@ -> usr/bin
drwxr-xr-x 2 root root 4096 Apr 20 08:46 boot/
drwxr-xr-x 1 root root 4096 Apr 21 02:06 dev/
drwxr-xr-x 1 root root 4096 May  6 01:07 etc/
drwxr-xr-x 3 root root 4096 Apr 21 17:23 home/
.....
.....

# アンマウント

root@dlp:~#
buildah umount $container

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

Getting image source signatures
Copying blob 0c3db79307ab skipped: already exists
Copying blob f421a7e99ead skipped: already exists
Copying blob a8943018aba0 done   |
Copying config 84ceb54861 done   |
Writing manifest to image destination
84ceb548618d757784fcbe53c9be922eb9fb245888baf41e4363f2a838ea56c7

root@dlp:~#
buildah images

REPOSITORY                 TAG      IMAGE ID       CREATED          SIZE
localhost/my-ubuntu        latest   84ceb548618d   16 seconds ago   194 MB
docker.io/library/ubuntu   latest   30ba44506a6d   2 weeks ago      111 MB

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

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

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

REPOSITORY                 TAG      IMAGE ID       CREATED          SIZE
localhost/my-ubuntu        latest   84ceb548618d   48 seconds ago   194 MB
docker.io/library/ubuntu   latest   30ba44506a6d   2 weeks ago      111 MB

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

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

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

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

root@node01:~#
podman images

REPOSITORY                       TAG         IMAGE ID      CREATED        SIZE
node01.srv.world:5000/my-ubuntu  latest      03c58cc53f05  7 minutes ago  147 MB
docker.io/library/registry       2           3a0f7b0a13ef  3 weeks ago    24.7 MB
関連コンテンツ