Ubuntu 22.04
Sponsored Link

Buildah : Install
2022/09/02
 
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 2b55860d4c66 done
Copying config 2dc39ba059 done
Writing manifest to image destination
Storing signatures
ubuntu-working-container

# show container list

root@dlp:~#
buildah containers

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
874af682530f     *     2dc39ba059dc 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   2dc39ba059dc   4 hours ago   80.4 MB

# possible to use images on podman

root@dlp:~#
podman images

REPOSITORY                TAG         IMAGE ID      CREATED      SIZE
docker.io/library/ubuntu  latest      2dc39ba059dc  4 hours ago  80.4 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@9ae231095c55:/#
apt-get update; apt-get -y install python3

root@9ae231095c55:/#
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/276840fef6aad0c0332656ccf310674136f9937763b00100d8e6b8f08e6dd8cd/merged
root@dlp:~#
ll /var/lib/containers/storage/overlay/276840fef6aad0c0332656ccf310674136f9937763b00100d8e6b8f08e6dd8cd/merged

total 80
dr-xr-xr-x 1 root root 4096 Sep  2 03:47 ./
drwx------ 5 root root 4096 Sep  2 03:50 ../
lrwxrwxrwx 1 root root    7 Aug 15 11:50 bin -> usr/bin/
drwxr-xr-x 2 root root 4096 Apr 18 10:28 boot/
drwxr-xr-x 2 root root 4096 Aug 15 11:53 dev/
drwxr-xr-x 1 root root 4096 Sep  2 03:48 etc/
.....
.....

root@dlp:~#
buildah umount $container

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

Getting image source signatures
Copying blob 7f5cbd8cc787 skipped: already exists
Copying blob 963b6ca318b0 done
Copying config 03c58cc53f done
Writing manifest to image destination
Storing signatures
03c58cc53f054930ea9b85faf233a97b2b7f128d55a8114b8f0fc8806b949a9c

root@dlp:~#
buildah images

REPOSITORY                 TAG      IMAGE ID       CREATED          SIZE
localhost/my-ubuntu        latest   03c58cc53f05   17 seconds ago   147 MB
docker.io/library/ubuntu   latest   2dc39ba059dc   4 hours ago      80.4 MB

# possible to use container images on podman

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

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

REPOSITORY                 TAG      IMAGE ID       CREATED         SIZE
localhost/my-ubuntu        latest   03c58cc53f05   4 minutes ago   147 MB
docker.io/library/ubuntu   latest   2dc39ba059dc   4 hours ago     80.4 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      03c58cc53f05  7 minutes ago  147 MB
docker.io/library/registry       2           3a0f7b0a13ef  3 weeks ago    24.7 MB
Matched Content