Containers
Buildah CLI
Buildah commands for OCI container image building.
30 commands
Windows
MacOS
Linux
#image-building
#oci
Container Management
Create a working container from an image
buildah from ubuntu:22.04
List all working containers
buildah containers
Run a command inside a container
buildah run mycontainer -- apt update
Copy files into a container
buildah copy mycontainer ./app /opt/app
Remove a working container
buildah rm mycontainer
Remove all working containers
buildah rm --all
Image Building
Build image from Dockerfile in current dir
buildah bud -t myimage:latest .
Build from a specific Dockerfile
buildah bud -f Dockerfile.prod -t myimage .
Commit a container to an image
buildah commit mycontainer myimage:v1
List all local images
buildah images
Remove a local image
buildah rmi myimage:v1
Tag an image for a registry
buildah tag myimage:v1 registry.io/myimage:v1
From Scratch
Create a container from an empty image
buildah from scratch
Copy a static binary into scratch container
buildah copy scratch-container ./binary /
Set the entrypoint
buildah config --entrypoint '["/binary"]' scratch-container
Expose a port in the image
buildah config --port 8080 scratch-container
Commit minimal image
buildah commit scratch-container minimal:latest
Configuration
Set an environment variable
buildah config --env APP_ENV=prod mycontainer
Set the working directory
buildah config --workingdir /opt/app mycontainer
Add a metadata label
buildah config --label version=1.0 mycontainer
Set the runtime user
buildah config --user appuser mycontainer
Set the default command
buildah config --cmd '["/app/start.sh"]' mycontainer
Push & Pull
Push image to a registry
buildah push myimage:v1 docker://registry.io/myimage:v1
Pull an image from a registry
buildah pull docker://nginx:alpine
Export image as OCI archive
buildah push myimage:v1 oci-archive:myimage.tar
Export as Docker archive
buildah push myimage:v1 docker-archive:myimage.tar
Import image from OCI archive
buildah pull oci-archive:myimage.tar
Quick Commands
Build a container image from a Dockerfile in the current directory
buildah bud -t myimage:latest .
Create a new working container based on an Ubuntu image
buildah from ubuntu:22.04
Commit a working container as a new image with a tag
buildah commit mycontainer myimage:v1