Buildah

On this page 7

Buildah is an open-source command-line tool for building container images that conform to the Open Container Initiative (OCI) and Docker image formats. Unlike the classic Docker build, it needs no background daemon and can run without root privileges, which makes it a common choice for secure image builds in containers and cloud CI pipelines.

Buildah was started by Red Hat and belongs to the same family of tools as Podman and Skopeo. It can build images from a Dockerfile or Containerfile, but it also exposes individual build steps as commands, so images can be assembled from shell scripts without any Dockerfile at all.

How Buildah builds images without a daemon

Buildah builds an image by creating a working container, modifying its filesystem and then committing it as an image layer. Each step runs as an ordinary process started by the user, not by a privileged service, so there is no long-running daemon and no Docker socket that grants root-equivalent access.

Storage is handled by the containers/storage library, which typically uses the overlay filesystem driver and keeps images in the user’s home directory for rootless builds. In rootless mode, Buildah relies on user namespaces: the user appears as root inside the build, while files map to unprivileged subordinate UIDs defined in /etc/subuid and /etc/subgid.

The most important Buildah subcommands map directly onto the stages of an image build.

CommandWhat it doesDockerfile equivalent
buildah fromCreates a working container from a base imageFROM
buildah runExecutes a command inside the working containerRUN
buildah copyCopies files from the host into the containerCOPY
buildah configSets metadata such as entrypoint, env and labelsENTRYPOINT, ENV, LABEL
buildah mountMounts the container filesystem on the hostNo direct equivalent
buildah commitSaves the container as a new imageEnd of build
buildah budBuilds from a Dockerfile or Containerfiledocker build
Core Buildah commands

Building with and without a Dockerfile

Buildah supports two styles of building. The command buildah build (historically buildah bud, short for build-using-dockerfile) reads a Dockerfile and produces the same result a Docker build would, including multi-stage builds. This path makes migration from Docker almost effortless.

The second style is scripted building. A shell script calls buildah from, buildah run and buildah commit in sequence, with full access to loops, conditionals and host tools. Combined with buildah mount, a script can install files with the host package manager directly into the image, producing minimal images without shells or package managers inside them, similar to a distroless image.

AspectDockerfile buildScripted build
PortabilityWorks with Docker, Podman and KanikoRequires Buildah on the build host
LogicLimited to Dockerfile instructionsFull shell logic and host tools
Layer controlOne layer per instruction by defaultLayers created only on commit
Image sizeDepends on base image toolingCan omit shells and package managers
ReadabilityFamiliar to most teamsRequires reading shell code
Dockerfile builds compared with scripted Buildah builds

Buildah compared with Docker and Podman

Buildah focuses only on building images, while related tools cover running containers or other build environments. Podman actually uses Buildah’s code for its own podman build command, so the two produce identical images; Buildah simply offers finer-grained control over each step.

ToolDaemon requiredRootless buildsMain purpose
BuildahNoYesBuilding OCI and Docker images
Docker with BuildKitYes, dockerdPossible in rootless modeBuilding and running containers
PodmanNoYesRunning containers, builds via Buildah code
KanikoNoRuns as root inside its containerBuilds inside Kubernetes pods
BuildKit standaloneYes, buildkitdYes, with rootless buildkitdHigh-performance parallel builds
Image build tools in the container ecosystem

Buildah outputs standard images that any OCI-compliant runtime can run, whether runc, crun or containerd, and it pushes them to any container registry with buildah push.

Using Buildah in CI pipelines

Buildah is especially valuable in continuous integration, where mounting the Docker socket into a build job effectively gives that job root access to the host. With Buildah, a CI runner can build images inside an unprivileged container, which reduces the attack surface of shared build infrastructure.

  • Use the vfs storage driver or fuse-overlayfs when overlay is unavailable inside a nested container.
  • Set --isolation chroot for builds inside containers that cannot create new namespaces.
  • Enable layer caching with --layers to reuse unchanged layers between builds.
  • Use --squash to merge layers when a single compact layer matters more than cache reuse.
  • Sign or scan the resulting image before pushing, because a rootless build is not automatically a secure image.

Limitations and common pitfalls

Rootless operation brings practical constraints that teams should plan for. The table below lists the most frequent problems and their usual fixes.

SymptomLikely causeFix
Permission denied on filesMissing subuid or subgid rangesAdd ranges to /etc/subuid and /etc/subgid
Very slow buildsFallback to the vfs driverEnable overlay or fuse-overlayfs
Cannot bind ports below 1024Rootless network limitsUse higher ports or adjust sysctl
Cache not reusedLayer caching not enabledBuild with –layers
Fails on macOS or WindowsBuildah needs a Linux kernelUse a Linux VM or Podman machine
Typical Buildah problems and fixes

Buildah is Linux-only and its scripted builds are less familiar than Dockerfiles, so teams that need broad portability usually keep a Dockerfile as the source of truth and use Buildah only as the build engine.

A non-technical view

A container image is like a packed lunchbox for software: it holds the program and everything it needs, ready to be opened on any computer.

Buildah is a tool for packing those lunchboxes. Older tools needed a permanent helper with master keys running in the background. Buildah does the packing itself, with only the permissions of the person using it. That makes it safer for shared build machines, where many teams work side by side.

A concrete example

A platform team runs a shared GitLab CI cluster on Kubernetes for about 40 development teams. The old pipeline mounted the Docker socket into build jobs, which meant any build job could take over its node. Security review flagged this as a critical risk.

The team replaces Docker builds with rootless Buildah running in unprivileged pods, using fuse-overlayfs storage and buildah build --layers with the existing Dockerfiles. For a Go service, a scripted build mounts an empty scratch container, copies in the static binary and CA certificates, and commits an image of about 15 MB instead of the previous 300 MB.

After the migration, no build job needs privileged access, average build times stay within 10 percent of the previous pipeline thanks to layer caching, and the cluster passes its next security audit without exceptions for the CI system.