Ubuntu 25.04
Sponsored Link

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

 

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

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

[1] Buildah をインストールします。
root@dlp:~#
apt -y install buildah
[2] 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 49b384cc7b4a done   |
Copying config bf3dc08bfe done   |
Writing manifest to image destination
ubuntu-working-container

# コンテナーリスト

root@dlp:~#
buildah containers

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
59bc8cd6c2eb     *     602eb6fb314b docker.io/library/ubuntu:latest  ubuntu-working-container

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

root@dlp:~#
buildah images

REPOSITORY                   TAG                IMAGE ID       CREATED             SIZE
docker.io/library/ubuntu     latest             602eb6fb314b   13 days ago         80.6 MB

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

root@dlp:~#
podman images

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

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@a91415edc762:/#
apt-get update; apt-get -y install python3

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

python3: /usr/bin/python3 /usr/lib/python3 /etc/python3 /usr/share/python3
[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/ae08afab6a867a123393df19bcf0b8a0a7442e4d14497e777beafb8252b509ca/merged
root@dlp:~#
ll /var/lib/containers/storage/overlay/ae08afab6a867a123393df19bcf0b8a0a7442e4d14497e777beafb8252b509ca/merged

total 76
dr-xr-xr-x 1 root root 4096 Apr 22 01:13 ./
drwx------ 5 root root 4096 Apr 22 01:14 ../
lrwxrwxrwx 1 root root    7 Apr 22  2024 bin -> usr/bin/
drwxr-xr-x 2 root root 4096 Apr 22  2024 boot/
drwxr-xr-x 2 root root 4096 Apr  4 02:09 dev/
drwxr-xr-x 1 root root 4096 Apr 22 01:14 etc/
drwxr-xr-x 3 root root 4096 Apr  4 02:09 home/
.....
.....

root@dlp:~#
buildah umount $container

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

Getting image source signatures
Copying blob 3abdd8a5e7a8 skipped: already exists
Copying blob 26cd0ed41c75 done   |
Copying config d5d623de80 done   |
Writing manifest to image destination
d5d623de80eb322baa1a46ce263ae75c239d83e5adb8add2747c46ca2879c5e9

root@dlp:~#
buildah images

REPOSITORY                   TAG                IMAGE ID       CREATED             SIZE
localhost/my-ubuntu          latest             d5d623de80eb   15 seconds ago      170 MB
docker.io/library/ubuntu     latest             602eb6fb314b   13 days ago         80.6 MB

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

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

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

REPOSITORY                   TAG                IMAGE ID       CREATED             SIZE
localhost/my-ubuntu          latest             d5d623de80eb   15 seconds ago      170 MB
docker.io/library/ubuntu     latest             602eb6fb314b   13 days ago         80.6 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      d5d623de80eb  7 minutes ago  170 MB
docker.io/library/registry       2           3a0f7b0a13ef  3 weeks ago    24.7 MB
関連コンテンツ