FreeBSD 14
Sponsored Link

Buildah : Create an image from Scratch2024/02/27

 

Create container images from an empty container image.

[1] For example, create a FreeBSD 14 container 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
df8bd4acf8be     *                  scratch                          working-container

# mount [scratch] container

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

root@dlp:~ #
echo $scratchmnt

/var/db/containers/storage/zfs/graph/44574456ecc4ecc5c70f9d063b8b9cb0b5a78ba9f5f876ad470652370fbdeecd

# install Base system

root@dlp:~ #
fetch https://download.freebsd.org/snapshots/amd64/14.0-STABLE/base.txz

root@dlp:~ #
fetch https://download.freebsd.org/snapshots/amd64/14.0-STABLE/lib32.txz

root@dlp:~ #
tar zxf base.txz -C $scratchmnt

root@dlp:~ #
tar zxf lib32.txz -C $scratchmnt

root@dlp:~ #
buildah umount $newcontainer

df8bd4acf8bebb959f08f6c66a54f44cdeb6798b53fd722887a305fb4db5053d

# submit your image to localhost

root@dlp:~ #
buildah commit $newcontainer freebsd-base:latest

Getting image source signatures
Copying blob e08c67379022 done   |
Copying config 2527bfa5ee done   |
Writing manifest to image destination
2527bfa5eeb403bf609aeba2e936eb49096e168fd74869885da52e27c4fc13d2

root@dlp:~ #
buildah images

REPOSITORY               TAG      IMAGE ID       CREATED              SIZE
localhost/freebsd-base   latest   2527bfa5eeb4   About a minute ago   1.05 GB

# run container

root@dlp:~ #
buildah run $newcontainer /bin/echo "Welcome to the Buildah World"

Welcome to the Buildah World
[2] Below are other basic operations.
Copy files into a working Container.
root@dlp:~ #
container=$(buildah from localhost/freebsd-base:latest)

root@dlp:~ #
echo "buildah test" > buildah.txt

root@dlp:~ #
buildah copy $container buildah.txt /tmp/buildah.txt

5f61e7f67676b5f9cdffc3ca0f3ba99f3fd9adf9e9c4d1e119037fccbb6fec89
root@dlp:~ #
buildah run $container cat /tmp/buildah.txt

buildah test
[3] Mount filesystem of a working Container.
root@dlp:~ #
buildah mount $container

/var/db/containers/storage/zfs/graph/bc152cb1ccb1bd78b41422bf97739470f1ad259461b9ff29dac9ddb770250ac0
root@dlp:~ #
ls -l /var/db/containers/storage/zfs/graph/bc152cb1ccb1bd78b41422bf97739470f1ad259461b9ff29dac9ddb770250ac0

total 94
-rw-r--r--   2 root wheel 1011 Feb 22 14:18 .cshrc
-rw-r--r--   2 root wheel  495 Feb 22 14:18 .profile
-r--r--r--   1 root wheel 6109 Feb 22 14:42 COPYRIGHT
drwxr-xr-x   2 root wheel   49 Feb 22 14:18 bin
drwxr-xr-x  14 root wheel   68 Feb 22 14:42 boot
dr-xr-xr-x   2 root wheel    2 Feb 22 13:53 dev
.....
.....

root@dlp:~ #
buildah umount $container

027dce4932cf916618c6e8e30cf45ad7d68573545365aa0c5e42b35db3f38f41
[4] Add a customized container image from a working Container.
root@dlp:~ #
buildah run $container /bin/sh
#
pkg install -y python310

#
exit
root@dlp:~ #
buildah commit $container freebsd-py310:latest

Getting image source signatures
Copying blob e08c67379022 skipped: already exists
Copying blob 7b4a90590e2d done   |
Copying config 153202042e done   |
Writing manifest to image destination
153202042e1f809ce3fe044be6d5ad153a8dba17de0a49e740aea13940bda562

root@dlp:~ #
buildah images

REPOSITORY                TAG      IMAGE ID       CREATED          SIZE
localhost/freebsd-py310   latest   153202042e1f   22 seconds ago   1.33 GB
localhost/freebsd-base    latest   2527bfa5eeb4   31 minutes ago   1.05 GB

root@dlp:~ #
buildah run $(buildah from localhost/freebsd-py310) which python3.10

/usr/local/bin/python3.10
Matched Content