What it does
buildah is the image builder of the Red Hat container tools (with podman to run and skopeo to copy images). It needs no daemon and no root, so it is a safe choice in CI runners and Kubernetes pods (no privileged docker-in-docker).
Two ways to work: buildah bud / buildah build reads a Dockerfile (Containerfile); or buildah from, run, copy, config, commit build an image step by step in a shell script.
How to write it
buildah build [OPTIONS] -t NAME[:TAG] [CONTEXT]
buildah from IMAGE → run / copy / config / commitMain parts
Commands
build,bud- Build from a Containerfile/Dockerfile.
fromIMAGE- Start a working container from a base image.
runCTR--CMD- Run a command in the working container.
copyCTRSRCDEST- Copy files into it.
config--cmd/--env/--port/--userCTR- Set image settings.
commitCTRNAME- Save the working container as an image.
pushIMAGEdocker://REG/IMAGE- Push to a registry.
images/containers/rm/rmi- List and remove.
loginREGISTRY- Log in to a registry.
manifestcreate/add/push- Multi-arch images.
Options 9
Most used
build options
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Build from a Dockerfile, rootless
buildah build -t shop:1.4.0 . buildah images2Push to a registry
buildah login ghcr.io buildah push shop:1.4.0 docker://ghcr.io/acme/shop:1.4.03Build step by step in a script
ctr=$(buildah from registry.access.redhat.com/ubi9/ubi-minimal) buildah run $ctr -- microdnf -y install nginx buildah copy $ctr ./site /usr/share/nginx/html buildah config --port 8080 --user 1001 --cmd "nginx -g 'daemon off;'" $ctr buildah commit $ctr web:1.0 buildah rm $ctr4Build inside an unprivileged GitLab CI job
cat .gitlab-ci.yml build: image: quay.io/buildah/stable script: - buildah build --isolation chroot -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA . - buildah push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA5Use a build argument
buildah build --build-arg VERSION=1.4.0 -t shop:1.4.0 .6Build for ARM
buildah build --platform linux/arm64 -t shop:1.4.0-arm64 .7A multi-arch image
buildah manifest create shop:1.4.0 buildah build --platform linux/amd64,linux/arm64 --manifest shop:1.4.0 . buildah manifest push --all shop:1.4.0 docker://ghcr.io/acme/shop:1.4.08Use the layer cache
buildah build --layers -t shop:dev .9List working containers and clean up
buildah containers buildah rm --all10Images built by buildah are seen by podman
podman run --rm -p 8080:8080 web:1.0
Nothing matches this filter.
Watch out
- Rootless builds need
/etc/subuidand/etc/subgidentries for the user. buildah runruns as root inside the container by default; set a non-root--userin the image config.
Files
/etc/containers/registries.conf- Registries and short-name rules.
~/.local/share/containers/- Rootless image storage.
Exit codes
0 | OK. |
1 | Error. |