CentOS 8
Sponsored Link

Buildah : インストール2019/10/11

 
コンテナーイメージ作成ツール Buildah をインストールします。
OCI (Open Container Initiative) イメージ フォーマットに準拠したコンテナーイメージを作成可能 且つ デーモン不要で利用できます。
[1] Buildah をインストールします。
[root@dlp ~]#
dnf -y install buildah
[2] Buildah の基本操作です。
イメージからワーキングコンテナーを新規作成する。
# [centos] イメージからワーキングコンテナー作成

[root@dlp ~]#
buildah from centos

Getting image source signatures
Copying blob sha256:729ec3a6ada3a6d26faca9b4779a037231f1762f759ef34c08bdd61bf52cd704
 68.21 MiB / 68.21 MiB  3s
Copying config sha256:0f3e07c0138fbe05abcb7a9cc7d63d9bd4c980c3f61fea5efa32e7c4217ef4da
 2.13 KiB / 2.13 KiB  0s
Writing manifest to image destination
Storing signatures
centos-working-container

# コンテナーリスト

[root@dlp ~]#
buildah containers

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
6d214b3e9b08     *     0f3e07c0138f docker.io/library/centos:latest  centos-working-container

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

[root@dlp ~]#
buildah images

IMAGE NAME                                               IMAGE TAG            IMAGE ID             CREATED AT             SIZE
docker.io/library/centos                                 latest               0f3e07c0138f         Oct 2, 2019 08:19      227 MB

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

[root@dlp ~]#
podman images

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

[root@dlp ~]#
container=$(buildah from centos)

[root@dlp ~]#
echo $container

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

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

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

[root@mrsdalloway /]#
dnf install python36

[root@mrsdalloway /]#
[root@dlp ~]#
buildah run $container whereis python3

python3: /usr/bin/python3.6 /usr/bin/python3.6m /usr/bin/python3 /usr/lib/python3.6 /usr/lib64/python3.6 /usr/include/python3.6m /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

ce9440fee6e37151fcc872dbf3fca2a77b95e66a627cabed14ba8349e1825607
[root@dlp ~]#
buildah run $container cat /tmp/buildah.txt

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

/var/lib/containers/storage/overlay/78d9a4e869dbf74dbac33ed685e50f9862cab4d91c2a5c37d1dfb076c33fcc48/merged
[root@dlp ~]#
ll /var/lib/containers/storage/overlay/78d9a4e869dbf74dbac33ed685e50f9862cab4d91c2a5c37d1dfb076c33fcc48/merged

total 0
lrwxrwxrwx. 1 root root  7 May 11 09:33 bin -> usr/bin
drwxr-xr-x. 2 root root  6 Sep 28 02:13 dev
drwxr-xr-x. 1 root root 37 Sep 28 02:13 etc
drwxr-xr-x. 2 root root  6 May 11 09:33 home
.....
.....

# アンマウント

[root@dlp ~]#
buildah umount $container

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

Getting image source signatures
Skipping fetch of repeat blob sha256:9e607bb861a7d58bece26dd2c02874beedd6a097c1b6eca5255d5eb0d2236983
Copying blob sha256:25ce4f51bd883962ed82c3932b94f748cbd3b7cab690533c9d6055948539bb2d
 21.49 MiB / 21.49 MiB  0s
Copying config sha256:0a3ba69587a4cc6abdcc951a8fe2ca4a63745263cac2b4bfcaa1e146c8730fff
 1.20 KiB / 1.20 KiB  0s
Writing manifest to image destination
Storing signatures
0a3ba69587a4cc6abdcc951a8fe2ca4a63745263cac2b4bfcaa1e146c8730fff
[root@dlp ~]#
buildah images

IMAGE NAME                                               IMAGE TAG            IMAGE ID             CREATED AT             SIZE
docker.io/library/centos                                 latest               0f3e07c0138f         Oct 2, 2019 08:19      227 MB
localhost/my-centos                                      latest               0a3ba69587a4         Oct 11, 2019 16:14     263 MB

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

[root@dlp ~]#
podman run localhost/my-centos hostname

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

IMAGE NAME                                               IMAGE TAG            IMAGE ID             CREATED AT             SIZE
docker.io/library/centos                                 latest               0f3e07c0138f         Oct 2, 2019 08:19      227 MB
localhost/my-centos                                      latest               0a3ba69587a4         Oct 11, 2019 16:14     263 MB

# [localhost/my-centos] イメージを [node01.srv.world:5000] へ Push する

# Push 先の registry が SSL/TLS 未対応の場合は [--tls-verify=false] オプション付加が必要

[root@dlp ~]#
buildah push --tls-verify=false localhost/my-centos node01.srv.world:5000/my-centos

Getting image source signatures
Copying blob sha256:9e607bb861a7d58bece26dd2c02874beedd6a097c1b6eca5255d5eb0d2236983
 216.91 MiB / 216.91 MiB  21s
Copying blob sha256:6827f6da87706c243a81476c7a110af0367c7f8ca91396b8ffb782c9edd3c5a8
 34.12 MiB / 34.12 MiB  4s
Copying config sha256:0a3ba69587a4cc6abdcc951a8fe2ca4a63745263cac2b4bfcaa1e146c8730fff
 1.20 KiB / 1.20 KiB  0s
Writing manifest to image destination
Storing signatures
Successfully pushed //node01.srv.world:5000/my-centos:latest@sha256:9384a0326fc7e68c628f84f4cd8443858dd85d782efba6b7b82fe0e9e1d85b87

[root@dlp ~]#
curl node01.srv.world:5000/v2/_catalog

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

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

[root@node01 ~]#
podman images

REPOSITORY                        TAG      IMAGE ID       CREATED          SIZE
node01.srv.world:5000/my-centos   latest   0a3ba69587a4   19 minutes ago   263 MB
docker.io/library/registry        2        f32a97de94e1   7 months ago     26.4 MB
関連コンテンツ