CentOS 8
Sponsored Link

Buildah : Install2019/10/11

 
Install Buildah that supports to create Container images.
It's possible to create OCI (Open Container Initiative) format image without specific Service Daemon.
[1] Install Buildah.
[root@dlp ~]#
dnf -y install buildah
[2] This is the basic usage for Buildah.
Create a working container from an image.
# create a working container from [centos] image

[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

# show container list

[root@dlp ~]#
buildah containers

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

# show container image list

[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

# possible to use images on podman

[root@dlp ~]#
podman images

REPOSITORY                 TAG      IMAGE ID       CREATED         SIZE
docker.io/library/centos   latest   0f3e07c0138f   9 days ago      227 MB
[3] Operate Working Container.
# set shell variable

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

[root@dlp ~]#
echo $container

centos-working-container-1
# possible to run commands

[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] Copy files into Working Container.
[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] Mount filesystem of Working Container.
[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
.....
.....

# unmount

[root@dlp ~]#
buildah umount $container

ac4361ea1e36a5f28b9c17e08365919ce53e06e3019ddb6e89861887abbd166d
[6] Create a container image from Working Container.
[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

# possible tp use container images on podman

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

048997d4002b
[7] Push a container image to specified Registry.
[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

# push [localhost/my-centos] image to [node01.srv.world:5000] registry

# if target registry is not on SSL/TLS, need [--tls-verify=false] option

[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"]}
# possible to Pull from other nodes

[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
Matched Content