openSUSE Leap 16

Buildah : インストール2025/11/03

 

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

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

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

dlp:~ #
buildah from opensuse/leap

Resolved "opensuse/leap" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull registry.opensuse.org/opensuse/leap:latest...
Getting image source signatures
Copying blob 84af677f62da done   |
Copying config 004d9956dc done   |
Writing manifest to image destination
leap-working-container

# コンテナーリスト

dlp:~ #
buildah containers

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
829267909ac0     *     004d9956dc10 registry.opensuse.org/opensus... leap-working-container

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

dlp:~ #
buildah images

REPOSITORY                            TAG      IMAGE ID       CREATED       SIZE
registry.opensuse.org/opensuse/leap   latest   004d9956dc10   2 weeks ago   118 MB

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

dlp:~ #
podman images

REPOSITORY                           TAG         IMAGE ID      CREATED      SIZE
registry.opensuse.org/opensuse/leap  latest      004d9956dc10  2 weeks ago  118 MB
[3] ワーキングコンテナーを操作する。
# シェル変数に格納可能

dlp:~ #
container=$(buildah from opensuse/leap)

dlp:~ #
echo $container

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

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

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

38e332989942:/ #
zypper -n install python3

38e332989942:/ #
dlp:~ #
buildah run $container python3 -V

Python 3.6.15
[4] ワーキングコンテナー内へファイルをコピーする。
dlp:~ #
echo "buildah test" > buildah.txt

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

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

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

/var/lib/containers/storage/overlay/773c1eb399f907f455d430ddaed872598ed713f250f72ad1d7575bfc738fc4c5/merged
dlp:~ #
ll /var/lib/containers/storage/overlay/773c1eb399f907f455d430ddaed872598ed713f250f72ad1d7575bfc738fc4c5/merged

total 0
drwxr-xr-x. 1 root root  440 Oct 17 05:08 bin
drwxr-xr-x. 1 root root    0 Mar 15  2022 boot
drwxr-xr-x. 1 root root    0 Mar 15  2022 dev
drwxr-xr-x. 1 root root   44 Oct 31 22:32 etc
drwxr-xr-x. 1 root root    0 Mar 15  2022 home
drwxr-xr-x. 1 root root   50 Oct 17 05:07 lib
drwxr-xr-x. 1 root root 1552 Oct 17 05:07 lib64
.....
.....

# アンマウント

dlp:~ #
buildah umount $container

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

Getting image source signatures
Copying blob 565e8c1e4903 skipped: already exists
Copying blob 4be48a724ccf done   |
Copying config 4e32bac039 done   |
Writing manifest to image destination
4e32bac0393988f9ffc99bfc4c512a714d1afdd0f45898b6909eee75459c9bb1

dlp:~ #
buildah images

REPOSITORY                            TAG      IMAGE ID       CREATED          SIZE
localhost/my-suse                     latest   4e32bac03939   16 seconds ago   425 MB
registry.opensuse.org/opensuse/leap   latest   004d9956dc10   2 weeks ago      118 MB

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

dlp:~ #
podman run localhost/my-suse cat /etc/os-release

NAME="openSUSE Leap"
VERSION="15.6"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.6"
PRETTY_NAME="openSUSE Leap 15.6"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.6"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"
DOCUMENTATION_URL="https://en.opensuse.org/Portal:Leap"
LOGO="distributor-logo-Leap"
[7] コンテナーイメージを指定の Registry へ Push する。
dlp:~ #
buildah images

REPOSITORY                            TAG      IMAGE ID       CREATED              SIZE
localhost/my-suse                     latest   4e32bac03939   About a minute ago   425 MB
registry.opensuse.org/opensuse/leap   latest   004d9956dc10   2 weeks ago          118 MB

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

dlp:~ #
buildah push --tls-verify=false localhost/my-suse node01.srv.world:5000/my-suse

Getting image source signatures
Copying blob 4be48a724ccf done   |
Copying blob 565e8c1e4903 done   |
Copying config 4e32bac039 done   |
Writing manifest to image destination

dlp:~ #
curl node01.srv.world:5000/v2/_catalog

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

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

node01:~ #
podman images

REPOSITORY                        TAG          IMAGE ID      CREATED        SIZE
node01.srv.world:5000/my-suse     latest       4e32bac03939  6 minutes ago  425 MB
関連コンテンツ