Debian 12 bookworm
Sponsored Link

Buildah : Create images from Scratch2023/06/21

 
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
4dfd63c8deb2     *     49081a1edb0b docker.io/library/debian:latest  debian-working-container
7279b5cfbac1     *     49081a1edb0b docker.io/library/debian:latest  debian-working-container-1
ca81bc5ed420     *                  scratch                          working-container

# mount [scratch] container

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

root@dlp:~#
echo $scratchmnt

/var/lib/containers/storage/overlay/a45ad1071206883b9559aae6dd59cf6ad44fa1a9ba6b74fad6cec01670182223/merged

# install packages to [scratch] container

root@dlp:~#
apt -y install debootstrap

root@dlp:~#
debootstrap bookworm $scratchmnt

# unmount

root@dlp:~#
buildah umount $newcontainer

ca81bc5ed4203414c464614b50168b696c48485b734a35d4a04a4776b4165e40

# run container

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

PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
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 226ddb469ebd done
Copying config d48f2ebebf done
Writing manifest to image destination
Storing signatures
d48f2ebebf104e2b4fd1d424057e73b80cdb41017136277503d743f6c9c1e175

root@dlp:~#
buildah images

REPOSITORY                   TAG       IMAGE ID       CREATED          SIZE
localhost/debian-basic       latest    d48f2ebebf10   19 seconds ago   297 MB
localhost/my-debian          latest    aeae4020349c   16 minutes ago   191 MB
docker.io/library/debian     latest    49081a1edb0b   8 days ago       121 MB

# test to run a container

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

Hello my debian
Matched Content