Difficulty: beginner
Estimated Time: 5-10 minutes

After completing this scenario, users will be able to build images from scratch or existing base images using buildah and other host based tools.

Concepts included in this scenario:

  • Initializing a working container for image building
  • Using buildah commands to modify a working container
  • Modfiying a working container with standard system tools
  • Creating an application image from a working container

Example Usecase:

Using podman with OCIFile or Dockerfile input is a common way to build containers from base images. However, this Building containers with buildah provides better control over layer creation and image contents.

NOTE: Throughout these steps there are UUIDs in output blocks that may not match your output exactly.

Author: Matthew Micene, Technical Content Manager (Red Hat)

Creating images with the container tools

Step 1 of 6

Step 1

Creating an application image from an existing base

Buildah has two main ways to create images:

  • Using subcommands to modify contents
  • Using host tools to modify a container filesystem

First, we'll look at using subcommands to modify the container contents before saving an image. Many buildah subcommands act like directives from an OCIfile. This allows for a familiar experience while automating builds.

The Red Hat Enterprise Linux 8 Universal Base Image is provided as the starting point for creating containers with Red Hat Enterprise Linux packages. More information on UBI can be found in the introductory blog post.

To build an application container from the ubi-init base image, we will create a working container with buildah. A working container is a temporary container used as the target for buildah commands.

buildah from registry.access.redhat.com/ubi8/ubi-init

ubi-init-working-container

This subcommand acts like the FROM directive in an OCIFile and makes the source image available on the host.

Buildah will append -working-container to the image name used. If that name already exists, a number will also be appended.