Fedora 41
Sponsored Link

Buildah : Install2024/11/07

 

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 [fedora] image

[root@dlp ~]#
buildah from fedora

Resolved "fedora" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull registry.fedoraproject.org/fedora:latest...
Getting image source signatures
Copying blob 0f779d0b7a52 done   |
Copying config 0e2b2f1016 done   |
Writing manifest to image destination
fedora-working-container

# show container list

[root@dlp ~]#
buildah containers

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
9e5f4bd9c78b     *     0e2b2f101698 registry.fedoraproject.org/fe... fedora-working-container

# show container image list

[root@dlp ~]#
buildah images

REPOSITORY                          TAG      IMAGE ID       CREATED        SIZE
registry.fedoraproject.org/fedora   latest   0e2b2f101698   17 hours ago   163 MB

# possible to use images on podman

[root@dlp ~]#
podman images

REPOSITORY                         TAG         IMAGE ID      CREATED       SIZE
registry.fedoraproject.org/fedora  latest      0e2b2f101698  17 hours ago  163 MB
[3] Operate Working Container.
# set shell variable

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

[root@dlp ~]#
echo $container

fedora-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@63d16a1f3443 /]#
dnf -y install python3

[root@63d16a1f3443 /]#
[root@dlp ~]#
buildah run $container python3 -V

Python 3.13.0
[4] Copy files into Working Container.
[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] Mount filesystem of Working Container.
[root@dlp ~]#
buildah mount $container

/var/lib/containers/storage/overlay/90c630e477f6006a171dd87f5a1c279265ec175c3e617f8f534a584e99facac6/merged
[root@dlp ~]#
ll /var/lib/containers/storage/overlay/90c630e477f6006a171dd87f5a1c279265ec175c3e617f8f534a584e99facac6/merged

total 0
dr-xr-xr-x. 2 root root  6 Jul 17 09:00 afs
lrwxrwxrwx. 1 root root  7 Jul 17 09:00 bin -> usr/bin
dr-xr-xr-x. 2 root root  6 Jul 17 09:00 boot
drwxr-xr-x. 2 root root  6 Nov  6 15:47 dev
drwxr-xr-x. 1 root root 60 Nov  7 08:48 etc
drwxr-xr-x. 2 root root  6 Jul 17 09:00 home
.....
.....

# unmount

[root@dlp ~]#
buildah umount $container

63d16a1f34430611268d16ba16ee003bd23e1afca499de28559ed48557a0a1bf
[6] Create a container image from Working Container.
[root@dlp ~]#
buildah commit $container my-fedora:latest

Getting image source signatures
Copying blob 92e30f8057f2 skipped: already exists
Copying blob dccf7e89f659 done   |
Copying config 0ee32bb622 done   |
Writing manifest to image destination
0ee32bb6225b75b98f331d24489b7c19b42bf7467ee3dc29a297050e23fdb099

[root@dlp ~]#
buildah images

REPOSITORY                          TAG      IMAGE ID       CREATED          SIZE
localhost/my-fedora                 latest   0ee32bb6225b   11 seconds ago   294 MB
registry.fedoraproject.org/fedora   latest   0e2b2f101698   17 hours ago     163 MB

# possible to use container images on podman

[root@dlp ~]#
podman run localhost/my-fedora uname -a

Linux f5ef10336ac2 6.11.5-300.fc41.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Oct 22 20:11:15 UTC 2024 x86_64 GNU/Linux
[7] Push a container image to a specified Registry.
[root@dlp ~]#
buildah images

REPOSITORY                          TAG      IMAGE ID       CREATED         SIZE
localhost/my-fedora                 latest   0ee32bb6225b   2 minutes ago   294 MB
registry.fedoraproject.org/fedora   latest   0e2b2f101698   17 hours ago    163 MB

# push [localhost/my-fedora] 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-fedora node01.srv.world:5000/my-fedora

Getting image source signatures
Copying blob 92e30f8057f2 done   |
Copying blob dccf7e89f659 done   |
Copying config 0ee32bb622 done   |
Writing manifest to image destination

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

{"repositories":["my-fedora"]}
# possible to Pull from other nodes

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

[root@node01 ~]#
podman images

REPOSITORY                       TAG         IMAGE ID      CREATED        SIZE
node01.srv.world:5000/my-fedora  latest      0ee32bb6225b  9 minutes ago  294 MB
Matched Content