Ubuntu 25.04
Sponsored Link

Buildah : Install2025/04/22

 

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:~#
apt -y install buildah
[2] This is the basic usage for Buildah.
Create a working container from an image.
# create a working container from [ubuntu] image

root@dlp:~#
buildah from ubuntu

Resolved "ubuntu" as an alias (/etc/containers/registries.conf.d/shortnames.conf)
Trying to pull docker.io/library/ubuntu:latest...
Getting image source signatures
Copying blob 49b384cc7b4a done   |
Copying config bf3dc08bfe done   |
Writing manifest to image destination
ubuntu-working-container

# show container list

root@dlp:~#
buildah containers

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
59bc8cd6c2eb     *     602eb6fb314b docker.io/library/ubuntu:latest  ubuntu-working-container

# show container image list

root@dlp:~#
buildah images

REPOSITORY                   TAG                IMAGE ID       CREATED             SIZE
docker.io/library/ubuntu     latest             602eb6fb314b   13 days ago         80.6 MB

# possible to use images on podman

root@dlp:~#
podman images

REPOSITORY                  TAG               IMAGE ID      CREATED            SIZE
docker.io/library/ubuntu    latest            602eb6fb314b  13 days ago        80.6 MB
[3] Operate Working Container.
# set shell variable

root@dlp:~#
container=$(buildah from ubuntu)

root@dlp:~#
echo $container

ubuntu-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@a91415edc762:/#
apt-get update; apt-get -y install python3

root@a91415edc762:/#
root@dlp:~#
buildah run $container whereis python3

python3: /usr/bin/python3 /usr/lib/python3 /etc/python3 /usr/share/python3
[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/ae08afab6a867a123393df19bcf0b8a0a7442e4d14497e777beafb8252b509ca/merged
root@dlp:~#
ll /var/lib/containers/storage/overlay/ae08afab6a867a123393df19bcf0b8a0a7442e4d14497e777beafb8252b509ca/merged

total 76
dr-xr-xr-x 1 root root 4096 Apr 22 01:13 ./
drwx------ 5 root root 4096 Apr 22 01:14 ../
lrwxrwxrwx 1 root root    7 Apr 22  2024 bin -> usr/bin/
drwxr-xr-x 2 root root 4096 Apr 22  2024 boot/
drwxr-xr-x 2 root root 4096 Apr  4 02:09 dev/
drwxr-xr-x 1 root root 4096 Apr 22 01:14 etc/
drwxr-xr-x 3 root root 4096 Apr  4 02:09 home/
.....
.....

root@dlp:~#
buildah umount $container

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

Getting image source signatures
Copying blob 3abdd8a5e7a8 skipped: already exists
Copying blob 26cd0ed41c75 done   |
Copying config d5d623de80 done   |
Writing manifest to image destination
d5d623de80eb322baa1a46ce263ae75c239d83e5adb8add2747c46ca2879c5e9

root@dlp:~#
buildah images

REPOSITORY                   TAG                IMAGE ID       CREATED             SIZE
localhost/my-ubuntu          latest             d5d623de80eb   15 seconds ago      170 MB
docker.io/library/ubuntu     latest             602eb6fb314b   13 days ago         80.6 MB

# possible to use container images on podman

root@dlp:~#
podman run localhost/my-ubuntu hostname

1c4f449a7ad8
[7] Push a container image to specified Registry.
root@dlp:~#
buildah images

REPOSITORY                   TAG                IMAGE ID       CREATED             SIZE
localhost/my-ubuntu          latest             d5d623de80eb   15 seconds ago      170 MB
docker.io/library/ubuntu     latest             602eb6fb314b   13 days ago         80.6 MB

# push [localhost/my-ubuntu] 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-ubuntu node01.srv.world:5000/my-ubuntu
root@dlp:~#
curl node01.srv.world:5000/v2/_catalog

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

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

root@node01:~#
podman images

REPOSITORY                       TAG         IMAGE ID      CREATED        SIZE
node01.srv.world:5000/my-ubuntu  latest      d5d623de80eb  7 minutes ago  170 MB
docker.io/library/registry       2           3a0f7b0a13ef  3 weeks ago    24.7 MB
Matched Content