A quick reference for Buildah โ daemonless OCI container image building. Bookmark this page.
Build from Containerfile
# Build image (like docker build)
buildah bud -t myapp:v1 .
buildah bud -t myapp:v1 -f Containerfile .
# Build with arguments
buildah bud --build-arg VERSION=3.11 -t myapp:v1 .
# Multi-stage build
buildah bud --layers -t myapp:v1 .
# Build without cache
buildah bud --no-cache -t myapp:v1 .
# Build for different platform
buildah bud --platform linux/arm64 -t myapp:v1-arm .Manual Image Building (No Dockerfile)
# Create a working container from base image
container=$(buildah from fedora:39)
# Run commands inside
buildah run $container -- dnf install -y nginx
buildah run $container -- dnf clean all
# Copy files into container
buildah copy $container ./app /opt/app
buildah copy $container nginx.conf /etc/nginx/nginx.conf
# Set configuration
buildah config --port 80 $container
buildah config --entrypoint '["/usr/sbin/nginx", "-g", "daemon off;"]' $container
buildah config --env APP_ENV=production $container
buildah config --label maintainer="luca@lucaberton.com" $container
buildah config --workingdir /opt/app $container
buildah config --user nginx $container
# Commit to image
buildah commit $container myapp:v1
# Clean up
buildah rm $containerImage Management
# List images
buildah images
# Inspect image
buildah inspect --type image myapp:v1
# Tag image
buildah tag myapp:v1 registry.example.com/myapp:v1
# Push to registry
buildah push myapp:v1 docker://registry.example.com/myapp:v1
# Push to Docker daemon
buildah push myapp:v1 docker-daemon:myapp:v1
# Remove image
buildah rmi myapp:v1
# Pull image
buildah pull docker.io/library/nginx:alpineContainer Management
# List working containers
buildah containers
# Mount container filesystem
mountpoint=$(buildah mount $container)
echo "Filesystem at: $mountpoint"
ls $mountpoint/etc/
# Unmount
buildah unmount $container
# Remove all containers
buildah rm -aTips and Tricks
- Buildah does not need a daemon โ perfect for CI/CD and rootless builds
- Use
buildah budfor Dockerfile/Containerfile builds (compatible with Docker) - Use manual building for fine-grained control and smaller images
- Combine with Podman:
podman builduses Buildah under the hood - Use
--squashto merge layers and reduce image size