About
Buildah is a lightweight and flexible command-line tool that you can use to create OCI-compliant container images without running a full Docker daemon. With Buildah, you can create a container based on a particular container image, update the contents of that container, and then create a brand new container image based on the altered container.
This cheat sheet shows you how to use Buildah to work with existing container images and build new ones. You’ll also walk through the basics of pushing a container to a container registry.
Download the Buildah Cheat Sheet and learn, including how to:
- Install buildah
- Pull, create, and delete container images
- Push container images to a container image registry
- Run, inspect, and delete a working container
With Red Hat Developer cheat sheets, you get essential information right at your fingertips so you can work faster and smarter. Easily learn new technologies and coding concepts and quickly find the answers you need.
Excerpt
Building a container image
buildah bud -t <image_name> <container_file_path>
Example:
The following example creates a container file and then builds a container image using that file.
Create the container file:
$ echo "echo This container works!" > myecho
$ chmod 755 myecho
$ cat << 'EOF' > Containerfile
FROM registry.access.redhat.com/ubi8/ubi
ADD myecho /tmp
ENTRYPOINT "/tmp/myecho"
EOF
$ buildah bud -t myecho-image Containerfile
Build the container image:
STEP 1/3: FROM registry.access.redhat.com/ubi8/ubi
STEP 2/3: ADD myecho /tmp
STEP 3/3: ENTRYPOINT "/tmp/myecho"
COMMIT myecho_image
Getting image source signatures
Copying blob 5bf135c4a0de skipped: already exists
Copying blob 773711fd02f0 skipped: already exists
Copying blob 12113fa850f7 done
Copying config b479141386 done
Writing manifest to image destination
Storing signatures
--> b4791413861
Successfully tagged localhost/myecho_image:latest
b4791413861b0245023d9781857000709f5c4ea22d464d16fcc6ce1b5daee2d5
List the container image:
$ buildah images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/myecho-image latest 636de016ba7a 9 seconds ago 225
MB
Inspect a container image
buildah inspect --type image image-id
or
buildah inspect --type image image-name
The buildah inspect command returns a very large JSON object that describes the many details of a container image.
Example:
The following example demonstrates executing the build inspect command against the image id a134be2e5346. The command produces a good deal of screen output. Thus the example shows a snippet of output:
buildah inspect --type image a134be2e5346
{
"Ty46307e5999d059bbfabafa43763318b90be569454474e9d2289cf9",
"FromImageDigest":
"sha256:ab86f8d2e3907728f9dcdeb62271e9f165b9dff6aa4507e352df97fc2e81e367",
"Config": "{\"created\":\"2022-06-14T18:16:42.578103429Z\",
\"architecture\":\"amd64\",\"os\":\"............\"}pe": "buildah 0.0.1",
"FromImage": "localhost/instrumentreseller:latest",
"FromImageID":
"a134be2e53
}