Fedora 33
Sponsored Link

Buildah : Install2020/11/06

 
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

Getting image source signatures
...
...
Writing manifest to image destination
Storing signatures
fedora-working-container

# show container list

[root@dlp ~]#
buildah containers

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
6eb265f49d8c     *     79fd58dc7611 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   79fd58dc7611   9 days ago   181 MB

# possible to use images on podman

[root@dlp ~]#
podman images

REPOSITORY                         TAG     IMAGE ID      CREATED     SIZE
registry.fedoraproject.org/fedora  latest  79fd58dc7611  9 days ago  181 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@173efa1d7495 /]#
dnf install python3

[root@173efa1d7495 /]#
[root@dlp ~]#
buildah run $container whereis python3

python3: /usr/bin/python3.9 /usr/bin/python3 /usr/lib/python3.9 /usr/lib64/python3.9 /usr/include/python3.9
[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/141c87f4f803ecdcca70413b4eb6eac8cb84f771306a3e79eb9e1f0c12e2e17a/merged
[root@dlp ~]#
ll /var/lib/containers/storage/overlay/141c87f4f803ecdcca70413b4eb6eac8cb84f771306a3e79eb9e1f0c12e2e17a/merged

total 0
lrwxrwxrwx.  1 root root   7 Jul 28 03:22 bin -> usr/bin
dr-xr-xr-x.  2 root root   6 Jul 28 03:22 boot
drwxr-xr-x.  2 root root   6 Oct 27 16:48 dev
drwxr-xr-x.  1 root root  38 Oct 27 16:48 etc
drwxr-xr-x.  2 root root   6 Jul 28 03:22 home
.....
.....

[root@dlp ~]#
buildah umount $container

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

Getting image source signatures
...
...
...
Writing manifest to image destination
Storing signatures
a5660f75edd5e175d17609ebbcbf3cd2cf0bcf337ab0f8085a5f0b7061b2942b
[root@dlp ~]#
buildah images

REPOSITORY                          TAG      IMAGE ID       CREATED          SIZE
localhost/my-fedora                 latest   a5660f75edd5   25 seconds ago   369 MB
registry.fedoraproject.org/fedora   latest   79fd58dc7611   9 days ago       181 MB

# possible tp use container images on podman

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

my fedora
Matched Content