Buildah is a command-line tool that builds container images without a daemon, which is a background service that has to stay running, like the Docker engine. It is the same build code that Podman uses under the hood, and every command runs directly in your shell. This walkthrough is for you if you build images in scripts or CI (continuous integration) pipelines and want tighter control over what ends up inside them.
Buildah produces OCI images, the standard format defined by the Open Container Initiative, so Docker, Podman and Kubernetes can all run them. You can build from a Dockerfile as usual, or skip it: start a working container, change its files like any ordinary folder, then commit the result as an image. Working step by step lets you decide what goes into each layer (one saved set of file changes in the image), which keeps production builds predictable and repeatable.
How to verify
After a Buildah install you should see the binary, the storage path, and a working rootless build:
buildah version
buildah info | grep -i graphroot
buildah from --pull alpine:3.19
buildah images
buildah containers
buildah inspect alpine-working-container
The from command pulls the base image and creates a “working container” — a writable mount of the rootfs. buildah containers lists these the way docker ps lists running processes, but they are not running, they are just open scratchpads waiting for your run/copy/config commands.
What’s happening
A Dockerfile is a declarative recipe: each line becomes a layer in the resulting image, and the daemon executes them in a sandboxed container. Buildah inverts the model — you imperatively create a container, mutate it however you like (run commands inside it, mount its rootfs and copy files in from outside, change its config), and commit the result as a new image. Each commit becomes a layer. You decide where the layer boundaries live.
This unlocks builds that Dockerfile cannot express cleanly: combining files from many sources into a single layer, mounting build-time secrets without leaving them in the layer, or building an image from scratch (no base image) by populating a tarball into a scratch rootfs. CI pipelines that produce minimal compliance-ready images frequently use this scratch approach to ship binaries with zero attack surface.
Buildah also reads Dockerfile and Containerfile directly with buildah bud (build-using-dockerfile) — so existing pipelines do not need to be rewritten to drop the daemon.
The procedure
- Build from an existing Dockerfile, daemon-free. The output is identical to
docker buildbut produced by a single rootless process:
cd /path/to/repo
buildah bud --tag registry.example.com/api:1.2.3 \
--layers \
--cache-to registry.example.com/api/cache \
--cache-from registry.example.com/api/cache \
.
--layers enables layer caching across builds (off by default in Buildah, unlike Docker). --cache-to/--cache-from uses a remote registry as the build cache, which is what CI runners need when they have no local state between jobs.
- Build without a Dockerfile, scripting the steps. This is the canonical example — a Python service in a
scratch-based image:
#!/bin/bash
set -euo pipefail
ctr=$(buildah from python:3.12-slim)
buildah copy "$ctr" ./requirements.txt /app/
buildah run --network host "$ctr" -- pip install --no-cache-dir -r /app/requirements.txt
buildah copy "$ctr" ./src /app/src
buildah config --workingdir /app "$ctr"
buildah config --user nobody "$ctr"
buildah config --port 8080 "$ctr"
buildah config --cmd '["python", "-m", "src.server"]' "$ctr"
buildah commit --rm "$ctr" registry.example.com/api:1.2.3
Every line is auditable. There is no RUN magic — buildah run shells into the container with its rootfs mounted, runs your command, unmounts cleanly.
- Inject build secrets without persisting them in the image. The mount only lives for the duration of
buildah run:
ctr=$(buildah from alpine:3.19)
buildah copy "$ctr" ./Gemfile* /app/
buildah run --mount=type=secret,id=github,src=$HOME/.config/github_token \
"$ctr" -- sh -c 'GITHUB_TOKEN=$(cat /run/secrets/github) bundle install'
buildah commit "$ctr" myapp:secret-free
After commit, myapp:secret-free has no trace of the token.
- Build a true scratch image — a single binary with nothing else:
ctr=$(buildah from scratch)
mount=$(buildah mount "$ctr")
cp ./bin/myapp "$mount/myapp"
buildah unmount "$ctr"
buildah config --entrypoint '["/myapp"]' "$ctr"
buildah commit "$ctr" registry.example.com/myapp:scratch
The resulting image is just your binary — 10 MB instead of 200 MB, no shell to exploit, nothing to CVE-scan.
- Push to a registry. Buildah uses the same
containers-auth.jsonas Podman and Skopeo:
buildah login registry.example.com
buildah push registry.example.com/api:1.2.3
Common pitfalls
- Forgetting
--layersand discovering that everybudbuilds from scratch with no cache reuse. Buildah’s default is “single layer per build” — opposite of Docker. - Running
buildah runagainst a base image whose/etc/resolv.confis empty — network calls inside the build will time out. Use--network hostto inherit the host resolver, or copy a workingresolv.confin. - Forgetting
--rmonbuildah commitand accumulating orphan working containers inbuildah containers. They eat disk on~/.local/share/containers/. - Building from a Dockerfile that uses
--mount=type=cacheand being surprised it works in Buildah too — but only with BuildKit-style syntax underbud --layers. Mixing flavors silently disables caching. - Mounting a working container with
buildah mountand forgetting tounmount— the OverlayFS layer remains and blocks future builds with the same name.
Stack Harbor uses Buildah for client CI pipelines that need to drop the Docker daemon — see managed operations for the rootless build runners, the remote layer cache pattern, and the scratch-image production builds we standardise.