Skip to content

Latest commit

 

History

History
182 lines (123 loc) · 4.24 KB

File metadata and controls

182 lines (123 loc) · 4.24 KB

Using Buildah

Whilst we do have a cockpit extension for managing containers via Podman, we’ll be interacting with Buildah on the command line.

We’re going to use the RHEL UBI minimal images to build these demo containers as these are freely redistributable base container images that are well maintained by Red Hat.

Pre-cache the base UBI Containers

This is a useful pre-step if you’re time constrained when using this content as a demo. You can pre-cache the Red Hat provided UBI base images allowing the build steps below to execute quicker.

buildah pull registry.access.redhat.com/ubi8/ubi-minimal
buildah pull registry.access.redhat.com/ubi8/ubi-micro

buildah images

Simple webserver container

On our build VM we will create a very simple webserver image with a dummy index.html

cd /opt/ephemeral-world/buildah
cd ubi-minimal-httpd
buildah build-using-dockerfile -t ubi-minimal-httpd .

buildah images

Then to test the image we’ll use podman

podman run -d -p 8000:80 --name simple-httpd localhost/ubi-minimal-httpd

podman ps

curl http://localhost:8000/

You can also look at the container via

podman ps
podman logs -f simple-httpd

# and stop the container
podman stop simple-httpd
podman rm simple-httpd

# and if we want we can clean up the built image
podman rmi localhost/ubi-minimal-httpd

Scripted vs Dockerfile

Here is an alternative approach (ubi-minimal-httpd.sh) where we script the build directly with buildah

This interacts directly with the container and then saves the final image.

cd /opt/ephemeral-world/buildah
cat ubi-minimal-httpd.sh

./ubi-minimal-httpd.sh

buildah images

We can test this again using podman

podman run -d -p 8000:80 --name simple-httpd localhost/ubi-minimal-scripted-httpd

podman ps

curl http://localhost:8000/

Once finished we can stop and clean up the container

podman stop simple-httpd
podman rm simple-httpd

Using ubi-micro Images

The newer Red Hat provided UBI Micro images are really really stripped down and don’t have any package management tooling like yum/dnf/microdnf. Hence we need to script any setup externally.

We’ve provided an equivalent build script for our webserver example ubi-micro-httpd.sh.

One additional gotacha is the build system has be a subscribed Red Hat Enterprise Linux instance, so we’ll use the RHEL 8.5 Demo VM from our Demo VM Setup guide.

cd /opt/ephemeral-world/buildah
cat ubi-micro-httpd.sh

./ubi-micro-httpd.sh

buildah images

We can test this again using podman

podman run -d -p 8000:80 --name simple-httpd localhost/ubi-micro-httpd

podman ps

curl http://localhost:8000/

Once finished we can stop and clean up the container

podman stop simple-httpd
podman rm simple-httpd

Red Hat Provided Apache Image

We could also leverage the offical Red Hat maintained pre-build Apache 2.4 image

podman login registry.redhat.io
Username: {REGISTRY-SERVICE-ACCOUNT-USERNAME}
Password: {REGISTRY-SERVICE-ACCOUNT-PASSWORD}


buildah pull registry.redhat.io/rhel8/httpd-24

Environment Cleanup

This will perform a full resource clean up of the container enviroment. It is pretty brute force so don’t use it on an environment with working containers.

podman stop -a
buildah rm  -a
buildah rmi -a
podman system prune

Bugs / Issues

You need to be careful of your RPM versions if you’re going to work with ubi-micro images. These images build outside of the container and your host needs to support the RPM database technology for the target image. For example you can’t build a RHEL8 ubi-micro image on Fedora 35 as it used a newer RPM DB format