Ubuntu 22.04
Sponsored Link

Buildah : Create images from Scratch
2022/09/02
 
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
874af682530f     *     2dc39ba059dc docker.io/library/ubuntu:latest  ubuntu-working-container
9ae231095c55     *     2dc39ba059dc docker.io/library/ubuntu:latest  ubuntu-working-container-1
d39c57e6b9e0     *                  scratch                          working-container

# mount [scratch] container

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

root@dlp:~#
echo $scratchmnt

/var/lib/containers/storage/overlay/f4760a70c2108d28b6a57a23ccc46d0a0c2179eca915b20605e27a9a182efd3f/merged

# install packages to [scratch] container

root@dlp:~#
apt -y install debootstrap

root@dlp:~#
debootstrap jammy $scratchmnt

# unmount

root@dlp:~#
buildah umount $newcontainer

d39c57e6b9e04f1f3e42acba73bbd949efc749dee1882d8453a0924509718a80

# run container

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

PRETTY_NAME="Ubuntu 22.04 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04 (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

# add images

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

Getting image source signatures
Copying blob c755a751394a done
Copying config bd3e7ec3b9 done
Writing manifest to image destination
Storing signatures
bd3e7ec3b902d468f990e5c6474674712ad2fac0e6f09bd6ed8533b63724c103

root@dlp:~#
buildah images

REPOSITORY                 TAG      IMAGE ID       CREATED          SIZE
localhost/ubuntu-basic     latest   bd3e7ec3b902   34 seconds ago   386 MB
localhost/my-ubuntu        latest   03c58cc53f05   18 minutes ago   147 MB
docker.io/library/ubuntu   latest   2dc39ba059dc   4 hours ago      80.4 MB

# test to run a container

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

Hello my debian
Matched Content