Thursday, November 27, 2025

 

Buildah : Create images from Scratch

 

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
e9f9b36a6e56     *     047bd8d81940 docker.io/library/debian:latest  debian-working-container
b1bd18cfd87d     *     047bd8d81940 docker.io/library/debian:latest  debian-working-container-1
7596c7a60413     *                  scratch                          working-container

# mount [scratch] container

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

root@dlp:~# 
echo $scratchmnt

/var/lib/containers/storage/overlay/9fb5c06eacfc5a84e11567194fe907b80843d4a0ec731848aaeb4f8291937eeb/merged

# install packages to [scratch] container

root@dlp:~# 
apt -y install debootstrap

root@dlp:~# 
debootstrap trixie $scratchmnt

# unmount

root@dlp:~# 
buildah umount $newcontainer

7596c7a6041388e860cfc19cf1e3eb37889acb7f28cf1ede5b213b30dfdc5bc4

# run container

root@dlp:~# 
buildah run $newcontainer cat /etc/os-release

PRETTY_NAME="Debian GNU/Linux 13 (trixie)"
NAME="Debian GNU/Linux"
VERSION_ID="13"
VERSION="13 (trixie)"
VERSION_CODENAME=trixie
DEBIAN_VERSION_FULL=13.0
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

# add images

root@dlp:~# 
buildah commit $newcontainer debian-basic:latest

Getting image source signatures
Copying blob 1cee239fdfc0 done   |
Copying config 8d1a03f855 done   |
Writing manifest to image destination
8d1a03f8551180ec205441df6d6f26c1df0e17cd9c4b90a0bf43196b895cf71b

root@dlp:~# 
buildah images

REPOSITORY                     TAG      IMAGE ID       CREATED          SIZE
localhost/debian-basic         latest   8d1a03f85511   17 seconds ago   307 MB
dlp.srv.world:5000/my-debian   latest   77fd1e5643fd   6 minutes ago    187 MB
localhost/my-debian            latest   77fd1e5643fd   6 minutes ago    187 MB
docker.io/library/debian       latest   047bd8d81940   11 days ago      124 MB

# test to run a container

root@dlp:~# 
podman run localhost/debian-basic /bin/echo "Hello my debian"

Hello my debian

No comments:

Post a Comment