CentOS 7
Sponsored Link

Buildah : インストール2018/08/30

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

[root@dlp ~]#
buildah from centos

Getting image source signatures
Copying blob sha256:256b176beaff7815db2a93ee2071621ae88f451bb1e198ca73010ed5bba79b65
 71.23 MiB / 71.23 MiB  4s
Copying config sha256:5182e96772bf11f4b912658e265dfe0db8bd314475443b6434ea708784192892
 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
c28ce3a30750     *     5182e96772bf docker.io/library/centos:latest  centos-working-container

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

[root@dlp ~]#
buildah images

IMAGE ID             IMAGE NAME                            CREATED AT             SIZE
5182e96772bf         docker.io/library/centos:latest       Aug 7, 2018 04:21      208 MB

# 特定のコンテナーイメージからではなくゼロから作成する場合は [scratch]

[root@dlp ~]#
buildah from scratch

working-container [root@dlp ~]#
buildah containers

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
c28ce3a30750     *     5182e96772bf docker.io/library/centos:latest  centos-working-container
df3709dc7552     *                  scratch                          working-container

# ゼロ開始のため実際のイメージはまだ作成されない

[root@dlp ~]#
buildah images

IMAGE ID             IMAGE NAME                             CREATED AT             SIZE
5182e96772bf         docker.io/library/centos:latest        Aug 7, 2018 04:21      208 MB
[3] ワーキングコンテナーを操作する。
# シェル変数に格納可能

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

[root@dlp ~]#
echo $container

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

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

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

[root@mrsdalloway /]#
yum install ruby

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

ruby: /usr/bin/ruby /usr/lib64/ruby /usr/share/ruby
[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 config --hostname my-hostname $container

[root@dlp ~]#
buildah run $container hostname

my-hostname
# ワーキングコンテナーの設定を表示

[root@dlp ~]#
buildah inspect $container

{
    "Type": "buildah 0.0.1",
    "FromImage": "docker.io/library/centos:latest",
    "FromImageID": "5182e96772bf11f4b912658e265dfe0db8bd314475443b6434ea708784192892",
.....
.....
        "config": {
            "Hostname": "my-hostname",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
.....
.....

# [buildah config] その他オプション

[root@dlp ~]#
buildah config -h

NAME:
   buildah config - Update image configuration settings

USAGE:
   buildah config [command options] CONTAINER-NAME-OR-ID

DESCRIPTION:
   Modifies the configuration values which will be saved to the image

OPTIONS:
   --annotation annotation, -a annotation   add annotation e.g. annotation=value, for the target image (default [])
   --arch architecture                      set architecture of the target image
   --author information                     set image author contact information
   --cmd command                            set the default command to run for containers based on the image
   --comment comment                        set a comment in the target image
   --created-by description                 set description of how the image was created
   --domainname name                        set a domain name for containers based on image
   --entrypoint entry point                 set entry point for containers based on image
   --env environment variable, -e .....     add environment variable to be set when running containers based on image (default [])
   --history-comment comment                set a comment for the history of the target image
   --hostname name                          set a hostname for containers based on image
   --label label, -l label                  add image configuration label e.g. label=value
   --onbuild value                          add onbuild command to be run on images based on this image. Only supported on 'docker' formatted images
   --os operating system                    set operating system of the target image
   --port port, -p port                     add port to expose when running containers based on image (default [])
   --shell shell                            add shell to run in containers
   --stop-signal stop signal                set stop signal for containers based on image
   --user user, -u user                     set default user to run inside containers based on image
   --volume volume, -v volume               add default volume path to be created for containers based on image (default [])
   --workingdir directory                   set working directory for containers based on image
[6] ワーキングコンテナーのファイルシステムをマウントする。
[root@dlp ~]#
buildah mount $container

/var/lib/containers/storage/overlay/58c70666c54601d8ce6c96c6079ed45ca60af25ff97cadc77cdfe2c937081b25/merged
[root@dlp ~]#
ll /var/lib/containers/storage/overlay/58c70666c54601d8ce6c96c6079ed45ca60af25ff97cadc77cdfe2c937081b25/merged

total 16
-rw-r--r--.  1 root root 12005 Aug  5 07:05 anaconda-post.log
lrwxrwxrwx.  1 root root     7 Aug  5 07:04 bin -> usr/bin
drwxr-xr-x.  2 root root     6 Aug  5 07:04 dev
drwxr-xr-x. 47 root root  4096 Aug  5 07:05 etc
drwxr-xr-x.  2 root root     6 Apr 11 13:59 home
.....
.....

# アンマウント

[root@dlp ~]#
buildah umount $container

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

Getting image source signatures
Skipping fetch of repeat blob sha256:1d31b5806ba40b5f67bde96f18a181668348934a44c9253b420d5f04cfb4e37a
Copying blob sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1
 32 B / 32 B  0s
Copying config sha256:4b5dfca9b6165627a7328eef35db5216f28c5c0504e05c2bb8d3e98a1d2382a3
 1.18 KiB / 1.18 KiB  0s
Writing manifest to image destination
Storing signatures
4b5dfca9b6165627a7328eef35db5216f28c5c0504e05c2bb8d3e98a1d2382a3
[root@dlp ~]#
buildah images

IMAGE ID             IMAGE NAME                             CREATED AT             SIZE
5182e96772bf         docker.io/library/centos:latest        Aug 7, 2018 04:21      208 MB
4b5dfca9b616         localhost/my-centos:latest             Aug 28, 2018 19:13     208 MB
[8] コンテナーイメージを指定の場所へ Push する。
[root@dlp ~]#
buildah images

IMAGE ID             IMAGE NAME                               CREATED AT             SIZE
5182e96772bf         docker.io/library/centos:latest          Aug 7, 2018 04:21      208 MB
4b5dfca9b616         localhost/my-centos:latest               Aug 28, 2018 17:13     208 MB

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

[root@dlp ~]#
buildah push localhost/my-centos www.srv.world:5000/my-centos

Getting image source signatures
Copying blob sha256:1d31b5806ba40b5f67bde96f18a181668348934a44c9253b420d5f04cfb4e37a
 198.64 MiB / 198.64 MiB  19s
Copying blob sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef
 1.00 KiB / 1.00 KiB  0s
Copying config sha256:4b5dfca9b6165627a7328eef35db5216f28c5c0504e05c2bb8d3e98a1d2382a3
 1.18 KiB / 1.18 KiB  0s
Writing manifest to image destination
Copying config sha256:4b5dfca9b6165627a7328eef35db5216f28c5c0504e05c2bb8d3e98a1d2382a3
 0 B / 1.18 KiB  0s
Writing manifest to image destination
Storing signatures

# 他の任意の Docker ノードから Pull 可能

[root@www ~]#
docker pull www.srv.world:5000/my-centos

[root@www ~]#
docker images

REPOSITORY                     TAG         IMAGE ID         CREATED          SIZE
www.srv.world:5000/my-centos   latest      4b5dfca9b616     40 hours ago     200 MB
docker.io/centos               latest      5182e96772bf     3 weeks ago      200 MB
docker.io/registry             2           b2b03e9146e1     7 weeks ago      33.3 MB
関連コンテンツ