Skip to main content

Buildah

Basic howto for building a container image with Buildah.

This example set will build the GNU hello application on a Fedora image. To follow along, download the hello source from here: http://mirrors.kernel.org/gnu/hello/

Start with a base image.

buildah from fedora:latest

Get a list of buildah containers

buildah containers

Screen Shot 2022-03-01 at 20.18.13.png

Set a container variable. (Reduces typing, great for scripting)

container=fedora-working-container

Copy the source to the container

buildah copy $container hello-2.12.14.tar.gz /tmp/

Install required packages into the container, then clear the package cache.

buildah run $container dnf install -y gzip tar gcc make automake
buildah run $container dnf clean all

Untar the source to /opt

buildah run $contaner tar zxvf /tmp/hello-2.12.tar.gz -C /opt

Set the working directory

buildah config --workingdir /opt/hello-2.12 $container

Build the software as required.

buildah run $container ./configure
buildah run $container autoconf
buildah run $container make
buildah run $container cp hello /usr/local/bin

Check the build and that the binary is in the correct location.

buildah run $container hello --version

Add an ENTRYPOINT

buildah config --entrypoint /usr/local/bin/hello $container

Commit the build container to an image.

buildah commit --format docker $container hello:latest

Screen Shot 2022-03-01 at 20.19.05.png

Run the image.

podman run hello

Remove the build directory

buildah rm $container