Rocky_Linux_8
Sponsored Link

Buildah : Create images from Scratch2021/07/30

 
Create container images from an empty container image.
[1] Start to create with [scratch] image.
# create an empty container with [scratch]

[root@dlp ~]#
newcontainer=$(buildah from scratch)

[root@dlp ~]#
buildah containers

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
28ae0a676f16     *     333da17614b6 docker.io/rockylinux/rockylin... rockylinux-working-container
2dc9c34b8aa8     *     333da17614b6 docker.io/rockylinux/rockylin... rockylinux-working-container-1
51793f2c03d3     *                  scratch                          working-container

# mount [scratch] container

[root@dlp ~]#
scratchmnt=$(buildah mount $newcontainer)

[root@dlp ~]#
echo $scratchmnt

/var/lib/containers/storage/overlay/7a90ab4f3df524428878260c544bcd403b2b77ed7e386867814fba546071e504/merged

# install packages to [scratch] container

[root@dlp ~]#
dnf -y group install "Minimal Install" --releasever=8 --installroot=$scratchmnt
# unmount

[root@dlp ~]#
buildah umount $newcontainer

51793f2c03d3516e084a0cbfdc83cc0dd1d492344bc570ca9517881a343c1137

# run container

[root@dlp ~]#
buildah run $newcontainer bash

[root@51793f2c03d3 /]#
[root@51793f2c03d3 /]#
cat /etc/os-release

NAME="Rocky Linux"
VERSION="8.4 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel fedora"
VERSION_ID="8.4"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.4 (Green Obsidian)"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:rocky:rocky:8.4:GA"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
ROCKY_SUPPORT_PRODUCT="Rocky Linux"
ROCKY_SUPPORT_PRODUCT_VERSION="8"

[root@51793f2c03d3 /]#
# add images

[root@dlp ~]#
buildah commit $newcontainer rockylinux-minimum:latest

Getting image source signatures
...
...
Writing manifest to image destination
Storing signatures
149ada9bc2680d702f8c56023977abe343d2055cc2c7e3de4c11a7707e809aab

[root@dlp ~]#
buildah images

REPOSITORY                        TAG      IMAGE ID       CREATED          SIZE
localhost/rockylinux-minimum      latest   149ada9bc268   53 seconds ago   1.42 GB
localhost/my-rockylinux           latest   5820cb7173a9   14 minutes ago   282 MB
docker.io/rockylinux/rockylinux   latest   333da17614b6   5 weeks ago      234 MB
Matched Content