buildah-build(1)

๐Ÿ’… buildah-build(1) ๐Ÿ’…

okay so bestie, welcome to the General Commands Manual page for buildah-build, and it's literally all about building an image using instructions from Containerfiles. No cap, this is the glow-up your container workflow needed. โœจ


โœจ NAME โœจ

buildah-build โ€” build an image using instructions from Containerfiles. ๐Ÿ’–

๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

buildah build [options] [context]

buildah bud [options] [context]

๐ŸŒธ DESCRIPTION ๐ŸŒธ

Builds an image using instructions from one or more Containerfiles or Dockerfiles and a specified build context directory. A Containerfile uses the same syntax as a Dockerfile internally. For this document, a file referred to as a Containerfile can be a file named either 'Containerfile' or 'Dockerfile'.

The build context directory can be specified as the http(s) URL of an archive, git repository or Containerfile.

If no context directory is specified, then Buildah will assume the current working directory as build context, which should contain a Containerfile.

Containerfiles ending with a .in suffix will be preprocessed via cpp(1). This can be useful to decompose Containerfiles into several reusable parts that can be used via CPP's #include directive. Notice, a Containerfile.in file can still be used by other tools when manually preprocessing them via cpp -E. Any comments (Lines beginning with #) in included Containerfile(s) that are not preprocess commands, will be printed as warnings during builds.

When the URL is an archive, the contents of the URL is downloaded to a temporary location and extracted before execution.

When the URL is a Containerfile, the file is downloaded to a temporary location.

When a Git repository is set as the URL, the repository is cloned locally and then used as the build context. A non-default branch (or commit ID) and subdirectory of the cloned git repository can be used by including their names at the end of the URL in the form myrepo.git#mybranch:subdir, myrepo.git#mycommit:subdir, or myrepo.git#:subdir if the subdirectory should be used from the default branch.


๐Ÿ’… OPTIONS ๐Ÿ’…

okay bestie, here come the flags, and there are a LOT. Every single one is iconic in its own way. ๐Ÿซถ

  • --add-host=[] โ€” add a custom host-to-IP mapping (host:ip). This literally adds a line to /etc/hosts, and the format is hostname:ip. The --add-host option can be set multiple times. Conflicts with the --no-hosts option.

Instead of an IP address, the special flag host-gateway can be given. This resolves to an IP address the container can use to connect to the host. The IP address chosen depends on your network setup, thus there's no guarantee that Buildah can determine the host-gateway address automatically, which will then cause Buildah to fail with an error message. You can overwrite this IP address using the host_containers_internal_ip option in containers.conf.

The host-gateway address is also used by Buildah to automatically add the host.containers.internal and host.docker.internal hostnames to /etc/hosts. You can prevent that by either giving the --no-hosts option, or by setting host_containers_internal_ip="none" in containers.conf. If no host-gateway address was configured manually and Buildah fails to determine the IP address automatically, Buildah will silently skip adding these internal hostnames to /etc/hosts. If Buildah is running in a virtual machine using podman machine (this includes Mac and Windows hosts), Buildah will silently skip adding the internal hostnames to /etc/hosts, unless an IP address was configured manually; the internal hostnames are resolved by the gvproxy DNS resolver instead.

Buildah will use the /etc/hosts file of the host as a basis by default, i.e. any hostname present in this file will also be present in the /etc/hosts file of the container. A different base file can be configured using the base_hosts_file config in containers.conf.

  • --all-platforms โ€” instead of building for a set of platforms specified using the --platform option, inspect the build's base images, and build for all of the platforms for which they are all available. Stages that use scratch as a starting point can not be inspected, so at least one non-scratch stage must be present for detection to work usefully. ๐Ÿ”
  • --annotation annotation[=value] โ€” add an image annotation (e.g. annotation=value) to the image metadata. Can be used multiple times. If annotation is named, but neither = nor a value is provided, then the annotation is set to an empty value.

Note: this information is not present in Docker image formats, so it is discarded when writing images in Docker formats. ๐Ÿ’€

  • --arch="ARCH" โ€” set the ARCH of the image to be built, and that of the base image to be pulled, if the build uses one, to the provided value instead of using the architecture of the host. (Examples: arm, arm64, 386, amd64, ppc64le, s390x) ๐Ÿ—๏ธ
  • --authfile path โ€” path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json. See containers-auth.json(5) for more information. This file is created using buildah login.

If the authorization state is not found there, $HOME/.docker/config.json is checked, which is set using docker login.

Note: you can also override the default path of the authentication file by setting the REGISTRY_AUTH_FILE environment variable. export REGISTRY_AUTH_FILE=path

  • --build-arg arg=value โ€” specifies a build argument and its value, which will be interpolated in instructions read from the Containerfiles in the same way that environment variables are, but which will not be added to environment variable list in the resulting image's configuration.

Please refer to the BUILD TIME VARIABLES section โŸจ#build-time-variablesโŸฉ for the list of variables that can be overridden within the Containerfile at run time. ๐Ÿ’–

  • --build-arg-file path โ€” specifies a file containing lines of build arguments of the form arg=value. The suggested file name is argfile.conf.

Comment lines beginning with # are ignored, along with blank lines. All others should be of the arg=value format passed to --build-arg.

If several arguments are provided via the --build-arg-file and --build-arg options, the build arguments will be merged across all of the provided files and command line arguments.

Any file provided in a --build-arg-file option will be read before the arguments supplied via the --build-arg option.

When a given argument name is specified several times, the last instance is the one that is passed to the resulting builds. This means --build-arg values always override those in a --build-arg-file. โœ…

  • --build-context name=value โ€” specify an additional build context using its short name and its location. Additional build contexts can be referenced in the same manner as we access different stages in COPY instruction.

Valid values could be:

  • Local directory โ€“ e.g. --build-context project2=../path/to/project2/src
  • HTTP URL to a tarball โ€“ e.g. --build-context src=https://example.org/releases/src.tar
  • Container image โ€“ specified with a container-image:// prefix, e.g. --build-context alpine=container-image://alpine:3.15, (also accepts docker://, docker-image://)

On the Containerfile side, you can reference the build context on all commands that accept the โ€œfromโ€ parameter. Hereโ€™s how that might look:

FROM [name]
COPY --from=[name] ...
RUN --mount=from=[name] โ€ฆ

The value of [name] is matched with the following priority order:

  1. Named build context defined with --build-context [name]=..
  2. Stage defined with AS [name] inside Containerfile
  3. Image [name], either local or in a remote registry
  • --cache-from โ€” repository to utilize as a potential list of cache sources. When specified, Buildah will try to look for cache images in the specified repositories and will attempt to pull cache images instead of actually executing the build steps locally. Buildah will only attempt to pull previously cached images if they are considered as valid cache hits.

Use the --cache-to option to populate a remote repository or repositories with cache content.

Example:

# populate a cache and also consult it
buildah build -t test --layers --cache-to registry/myrepo/cache --cache-from registry/myrepo/cache .

Note: --cache-from option is ignored unless --layers is specified.

Note: Buildah's --cache-from option is designed differently than Docker and BuildKit's --cache-from option. Buildah's distributed cache mechanism pulls intermediate images from the remote registry itself, unlike Docker and BuildKit where the intermediate image is stored in the image itself. Buildah's approach is similar to kaniko, which does not inflate the size of the original image with intermediate images. Also, intermediate images can truly be kept distributed across one or more remote registries using Buildah's caching mechanism. ๐Ÿง 

  • --cache-to โ€” set this flag to specify list of remote repositories that will be used to store cache images. Buildah will attempt to push newly built cache image to the remote repositories.

Note: use the --cache-from option in order to use cache content in a remote repository.

Example:

# populate a cache and also consult it
buildah build -t test --layers --cache-to registry/myrepo/cache --cache-from registry/myrepo/cache .

Note: --cache-to option is ignored unless --layers is specified.

Note: Buildah's --cache-to option is designed differently than Docker and BuildKit's --cache-to option. Buildah's distributed cache mechanism push intermediate images to the remote registry itself, unlike Docker and BuildKit where the intermediate image is stored in the image itself. Buildah's approach is similar to kaniko, which does not inflate the size of the original image with intermediate images. Also, intermediate images can truly be kept distributed across one or more remote registries using Buildah's caching mechanism. ๐Ÿ”ฅ

  • --cache-ttl duration โ€” limit the use of cached images to only consider images with created timestamps less than duration ago. For example if --cache-ttl=1h is specified, Buildah will only consider intermediate cache images which are created under the duration of one hour, and intermediate cache images outside this duration will be ignored. โณ

Note: setting --cache-ttl=0 manually is equivalent to using --no-cache in the implementation since this would effectively mean that user is not willing to use cache at all.

  • --cap-add=CAP_xxx โ€” when executing RUN instructions, run the command specified in the instruction with the specified capability added to its capability set. Certain capabilities are granted by default; this option can be used to add more. ๐Ÿ’ช
  • --cap-drop=CAP_xxx

so when a RUN instruction fires, the command runs with that capability removed from its capability set. And just so you know what's in the starting lineup: CAP_CHOWN, CAP_DAC_OVERRIDE, CAP_FOWNER, CAP_FSETID, CAP_KILL, CAP_NET_BIND_SERVICE, CAP_SETFCAP, CAP_SETGID, CAP_SETPCAP, and CAP_SETUID all come granted by default โ€” this option is how you take them away. The whole default list is managed over in containers.conf(5) if you wanna peek. ๐Ÿ‘€

โš ๏ธ real talk: if you specify the same capability in both --cap-add and --cap-drop, it gets dropped, periodt. Order of the options does not matter, so don't try to be slick with it. ๐Ÿ’€
  • --cert-dir path โ€” use the certs chillin' at path (*.crt, *.cert, *.key) to connect to the registry, and to pull stuff from HTTPS locations for ADD instructions. The default certs directory is /etc/containers/certs.d. ๐ŸŽ€
  • --cgroup-parent="" โ€” the path to the cgroups where the cgroup for RUN instructions gets created. If the path isn't absolute, it's treated as relative to the cgroups path of the init process. Cgroups get created if they don't already exist โ€” no cap. โœจ
  • --cgroupns how โ€” sets the config for cgroup namespaces when handling RUN instructions. The value can be "" (the empty string, yes literally) or "private" to say "make a brand new cgroup namespace pls", or "host" to say "reuse the cgroup namespace buildah itself is running in". ๐Ÿฆ‹
  • --compat-volumes โ€” handles directories marked with the VOLUME instruction (both the ones in this build and the ones inherited from base images) so that their contents can only be modified by ADD and COPY instructions. Any changes RUN makes in those spots get reverted. The lore: before this option existed, this was the default behavior, but now it's disabled by default. So this flag brings the old vibe back. ๐ŸŒธ
  • --compress โ€” ok so this one is literally just here to be aligned with other containers CLIs. Buildah doesn't send a copy of the context directory to a daemon or a remote server, so compressing the data before sending it is irrelevant to Buildah. It's giving "invited to the party but has no job." ๐Ÿ’…
  • --compression-format format โ€” specifies the compression format to use. Supported values are: gzip, zstd and zstd:chunked. Heads up: zstd:chunked is incompatible with encrypting images, and will be treated as zstd with a warning in that case. If you don't specify, the format is read from the compression_format setting in containers.conf.

This option affects cache pushes with --cache-to and the final image when it's written to a non-local destination (e.g., dir:, oci:, oci-archive:, or a registry). When the output is local container storage (the default), layers are always decompressed on ingest, so compression gets applied at buildah push time instead. ๐Ÿซถ

  • --compression-level level โ€” specifies the compression level to use. The value is specific to the compression algorithm, e.g. for zstd the accepted values are in the range 1-20 (inclusive), while for gzip it's 1-9 (inclusive). If not specified, the level is read from the compression_level setting in containers.conf. ๐Ÿ“Š
  • --cpp-flag="" โ€” set extra flags to pass to the C Preprocessor cpp(1). Containerfiles ending with a .in suffix get preprocessed via cpp(1), and this option is how you pass additional flags to cpp. Note: you can also set default CPPFLAGS by setting the BUILDAH_CPPFLAGS environment variable (e.g., export BUILDAH_CPPFLAGS="-DDEBUG"). ๐Ÿงš
  • --cpu-period=0 โ€” sets the CPU period for the Completely Fair Scheduler (CFS), which is a duration in microseconds. Once the container's CPU quota is used up, it will not be scheduled to run until the current period ends. Defaults to 100000 microseconds.

On some systems, changing the CPU limits may not be allowed for non-root users. For more details, see: https://github.com/containers/podman/blob/main/troubleshooting.md#26-running-containers-with-cpu-limits-fails-with-a-permissions-error ๐Ÿ˜ญ

  • --cpu-quota=0 โ€” limit the CPU CFS (Completely Fair Scheduler) quota. Limit the container's CPU usage. By default, containers run with the full CPU resource; this flag tells the kernel to restrict the container's CPU usage to the quota you specify.

On some systems, changing the CPU limits may not be allowed for non-root users. For more details, see: https://github.com/containers/podman/blob/main/troubleshooting.md#26-running-containers-with-cpu-limits-fails-with-a-permissions-error ๐Ÿ˜ญ

  • --cpu-shares, -c=0 โ€” CPU shares (relative weight).

By default, all containers get the same proportion of CPU cycles. You can modify that proportion by changing the container's CPU share weighting relative to the weighting of all the other running containers.

To modify the proportion from the default of 1024, use the --cpu-shares flag to set the weighting to 2 or higher.

The proportion only applies when CPU-intensive processes are running. When tasks in one container are idle, other containers can use the left-over CPU time. The actual amount of CPU time will vary depending on how many containers are running on the system.

For example, consider three containers โ€” one has a cpu-share of 1024 and two others have a cpu-share setting of 512. When processes in all three containers attempt to use 100% of CPU, the first container would receive 50% of the total CPU time. If you add a fourth container with a cpu-share of 1024, the first container only gets 33% of the CPU. The remaining containers receive 16.5%, 16.5% and 33% of the CPU. Math slay. ๐Ÿงฎ

On a multi-core system, the shares of CPU time are distributed over all CPU cores. Even if a container is limited to less than 100% of CPU time, it can use 100% of each individual CPU core.

For example, consider a system with more than three cores. If you start one container {C0} with -c=512 running one process, and another container {C1} with -c=1024 running two processes, this can result in the following division of CPU shares:

PID    container    CPU  CPU share
100    {C0}         0    100% of CPU0
101    {C1}         1    100% of CPU1
102    {C1}         2    100% of CPU2
  • --cpuset-cpus="" โ€” CPUs in which to allow execution (0-3, 0,1). Pin it, bestie. ๐Ÿ“Œ
  • --cpuset-mems="" โ€” memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.

So like, if you have four memory nodes on your system (0-3), use --cpuset-mems=0,1 and then processes in your container will only use memory from the first two memory nodes. ๐Ÿง 

  • --created-annotation โ€” add an image annotation (see also --annotation) to the image metadata, setting "org.opencontainers.image.created" to the current time, or to the datestamp specified to the --source-date-epoch or --timestamp flag, if either was used. If false, no such annotation will be present in the written image.

Note: this information is not present in Docker image formats, so it gets discarded when writing images in Docker formats. ๐Ÿ™ˆ

  • --creds creds โ€” the [username[:password]] to use to authenticate with the registry if required. If one or both values are not supplied, a command line prompt will appear and you can enter the value. The password is entered without echo โ€” sneaky sneaky, love that for us. ๐Ÿ”
  • --cw options โ€” produce an image suitable for use as a confidential workload running in a trusted execution environment (TEE) using krun (i.e., crun built with the libkrun feature enabled and invoked as krun). Instead of the conventional contents, the root filesystem of the image will contain an encrypted disk image and configuration information for krun. ๐Ÿ•ต๏ธโ€โ™€๏ธ

The value for options is a comma-separated list of key=value pairs, supplying configuration information which is needed for producing the additional data that gets included in the container image.

Recognized keys are:

  • attestation_url: the location of a key broker / attestation server. If a value is specified, the new image's workload ID, along with the passphrase used to encrypt the disk image, will be registered with the server, and the server's location will be stored in the container image. At run-time, krun is expected to contact the server to retrieve the passphrase using the workload ID, which is also stored in the container image. If no value is specified, a passphrase value must be specified.
  • cpus: the number of virtual CPUs which the image expects to be run with at run-time. If not specified, a default value will be supplied.
  • firmware_library: the location of the libkrunfw-sev shared library. If not specified, buildah checks for its presence in a number of hard-coded locations.
  • memory: the amount of memory which the image expects to be run with at run-time, as a number of megabytes. If not specified, a default value will be supplied.
  • passphrase: the passphrase to use to encrypt the disk image which will be included in the container image. If no value is specified, but an attestation_url value is specified, a randomly-generated passphrase will be used. The authors recommend setting an attestation_url but not a passphrase. ๐Ÿ’–
  • slop: extra space to allocate for the disk image compared to the size of the container image's contents, expressed either as a percentage (..%) or a size value (bytes, or larger units if suffixes like KB or MB are present), or a sum of two or more such specifications. If not specified, buildah guesses that 25% more space than the contents will be enough, but this option is provided in case its guess is wrong. (It's giving "trust me bro" but with a manual override.) ๐Ÿ’€
  • type: the type of trusted execution environment (TEE) which the image should be marked for use with. Accepted values are "SEV" (AMD Secure Encrypted Virtualization - Encrypted State) and "SNP" (AMD Secure Encrypted Virtualization - Secure Nested Paging). If not specified, defaults to "SNP".
  • workload_id: a workload identifier which will be recorded in the container image, to be used at run-time for retrieving the passphrase which was used to encrypt the disk image. If not specified, a semi-random value will be derived from the base image's image ID.
  • --decryption-key key[:passphrase] โ€” the [key[:passphrase]] to be used for decryption of images. key can point to keys and/or certificates. Decryption will be tried with all keys. If the key is protected by a passphrase, it is required to be passed in the argument and omitted otherwise. ๐Ÿ—๏ธ
  • --device= device โ€” add a host device, or devices under a directory, to the environment of any RUN instructions run during the build. The optional permissions parameter can be used to specify device permissions, using any one or more of r for read, w for write, and m for mknod(2).

Example: --device=/dev/sdc:/dev/xvdc:rwm.

Note: if host-device is a symbolic link then it will be resolved first. The container will only store the major and minor numbers of the host device. ๐Ÿ”Œ


...and bestie, that device to share can also be specified using a Container Device Interface (CDI) specification โ€” like, the whole spec lives at https://github.com/cncf-tags/container-device-interface ๐Ÿ’…

โš ๏ธ ok important heads-up: if you only have access rights via a group, accessing the device from inside a rootless container will fail. The crun(1) runtime offers a workaround for this by adding the option --annotation run.oci.keep_original_groups=1. Noted, saved, memorized ๐Ÿซถ
  • --disable-compression, -D โ€” don't compress filesystem layers when building the image unless it is required by the location where the image is being written. This is the default setting, because image layers are compressed automatically when they are pushed to registries, and images being written to local storage would only need to be decompressed again to be stored. Compression can be forced in all cases by specifying --disable-compression=false. โœจ
  • --disable-content-trust โ€” this is a Docker specific option to disable image verification to a Container registry and is not supported by Buildah. This flag is a NOOP and provided solely for scripting compatibility. So like... it does literally nothing here, it's just there so your scripts don't cry ๐Ÿ’€
  • --dns=[] โ€” set custom DNS servers. Invalid if using --dns with --network=none.

This option can be used to override the DNS configuration passed to the container. Typically this is necessary when the host DNS configuration is invalid for the container (e.g., 127.0.0.1). When this is the case the --dns flag is necessary for every run.

The special value none can be specified to disable creation of /etc/resolv.conf in the container by Buildah. The /etc/resolv.conf file in the image will be used without changes. ๐Ÿฆ‹

  • --dns-option=[] โ€” set custom DNS options. Invalid if using --dns-option with --network=none. ๐ŸŽ€
  • --dns-search=[] โ€” set custom DNS search domains. Invalid if using --dns-search with --network=none. ๐ŸŽ€
  • --env env[=value] โ€” add a value (e.g. env=value) to the built image. Can be used multiple times. If neither = nor a value are specified, but env is set in the current environment, the value from the current environment will be added to the image. The value of env can be overridden by ENV instructions in the Containerfile. To remove an environment variable from the built image, use the --unsetenv option. ๐Ÿงš
  • --file, -f Containerfile โ€” specifies a Containerfile which contains instructions for building the image, either a local file or an http or https URL. If more than one Containerfile is specified, FROM instructions will only be accepted from the last specified file.

If a local file is specified as the Containerfile and it does not exist, the context directory will be prepended to the local file value.

If you specify -f -, the Containerfile contents will be read from stdin. ๐Ÿ‘‘

  • --force-compression โ€” if set, uses the specified compression algorithm even if the destination contains a differently-compressed variant already. Defaults to true if --compression-format is explicitly specified on the command-line or compression_format is set in containers.conf, false otherwise.
  • --force-rm bool-value โ€” always remove intermediate containers after a build, even if the build fails (default false). literally "clean up your mess no matter what" energy ๐Ÿ”ฅ
  • --format โ€” control the format for the built image's manifest and configuration data. Recognized formats include oci (OCI image-spec v1.0, the default) and docker (version 2, using schema format 2 for the manifest).
๐Ÿ’ก Note: You can also override the default format by setting the BUILDAH_FORMAT environment variable. Like: export BUILDAH_FORMAT=docker
  • --from โ€” overrides the first FROM instruction within the Containerfile. If there are multiple FROM instructions in a Containerfile, only the first is changed. Just the first, bestie, don't get greedy ๐Ÿ™ˆ
  • --group-add=group | keep-groups โ€” assign additional groups to the primary user running within the container process.
    • keep-groups is a special flag that tells Buildah to keep the supplementary group access.

Allows container to use the user's supplementary group access. If file systems or devices are only accessible by the rootless user's group, this flag tells the OCI runtime to pass the group access into the container. Currently only available with the crun OCI runtime. Note: keep-groups is exclusive, other groups cannot be specified with this flag. โญ

  • --help, -h โ€” print usage statement. the classic. the icon. when in doubt, -h ๐Ÿ’–
  • --hooks-dir path โ€” each *.json file in the path configures a hook for buildah build containers. For more details on the syntax of the JSON files and the semantics of hook injection, see oci-hooks(5). Buildah currently support both the 1.0.0 and 0.1.0 hook schemas, although the 0.1.0 schema is deprecated.

This option may be set multiple times; paths from later options have higher precedence (oci-hooks(5) discusses directory precedence).

For the annotation conditions, buildah uses any annotations set in the generated OCI configuration.

For the bind-mount conditions, only mounts explicitly requested by the caller via --volume are considered. Bind mounts that buildah inserts by default (e.g. /dev/shm) are not considered.

If --hooks-dir is unset for root callers, Buildah will currently default to /usr/share/containers/oci/hooks.d and /etc/containers/oci/hooks.d in order of increasing precedence. Using these defaults is deprecated, and callers should migrate to explicitly setting --hooks-dir. ๐Ÿ˜ญ (migrate pls)

  • --http-proxy=true โ€” by default proxy environment variables are passed into the container if set for the buildah process. This can be disabled by setting the --http-proxy option to false. The environment variables passed in include http_proxy, https_proxy, ftp_proxy, no_proxy, and also the upper case versions of those. ๐Ÿซถ
  • --identity-label bool-value โ€” adds a label io.buildah.version with its value set to the version of buildah which built the image (default true unless --timestamp or --source-date-epoch is used). ๐ŸŽ€
  • --ignorefile file โ€” path to an alternative .containerignore (.dockerignore) file. like a lil "ignore these pls" guest list ๐Ÿ’…
  • --iidfile ImageIDfile โ€” write the built image's ID to the file. When --platform is specified more than once, attempting to use this option will trigger an error. โš ๏ธ
  • --iidfile-raw ImageIDfile โ€” write the built image's ID to the file without the algorithm prefix (e.g., sha256:). When --platform is specified more than once, attempting to use this option will trigger an error.

An alias --raw-iidfile is also available. โœจ

  • --inherit-annotations bool-value โ€” inherit the annotations from the base image or base stages. (default true). Use cases which set this flag to false may need to do the same for the --created-annotation flag. ๐Ÿฆ‹
  • --inherit-labels bool-value โ€” inherit the labels from the base image or base stages. (default true). ๐Ÿฆ‹
  • --ipc how โ€” sets the configuration for IPC namespaces when handling RUN instructions. The configured value can be "" (the empty string) or "container" to indicate that a new IPC namespace should be created, or it can be "host" to indicate that the IPC namespace in which buildah itself is being run should be reused, or it can be the path to an IPC namespace which is already in use by another process. ๐ŸŒˆ
  • --isolation type โ€” controls what type of isolation is used for running processes as part of RUN instructions. Recognized types include oci (OCI-compatible runtime, the default), rootless (OCI-compatible runtime invoked using a modified configuration, with --no-new-keyring added to its create invocation, reusing the host's network and UTS namespaces, and creating private IPC, PID, mount, and user namespaces; the default for unprivileged users), and chroot (an internal wrapper that leans more toward chroot(1) than container technology, reusing the host's control group, network, IPC, and PID namespaces, and creating private mount and UTS namespaces, and creating user namespaces only when they're required for ID mapping).
๐Ÿ’ก Note: You can also override the default isolation type by setting the BUILDAH_ISOLATION environment variable. Like: export BUILDAH_ISOLATION=oci
  • --jobs N โ€” run up to N concurrent stages in parallel. If the number of jobs is greater than 1, stdin will be read from /dev/null. If 0 is specified, then there is no limit on the number of jobs that run in parallel. multitasking queen behavior ๐Ÿ‘‘
  • --label label[=value] โ€” add an image label (e.g. label=value) to the image metadata. Can be used multiple times. If label is named, but neither = nor a value is provided, then the label is set to an empty value.

Users can set a special LABEL io.containers.capabilities=CAP1,CAP2,CAP3 in a Containerfile that specifies the list of Linux capabilities required for the container to run properly. This label specified in a container image tells container engines, like Podman, which recognize this label to run the container with just these capabilities. The container engine launches the container with just the specified capabilities, as long as this list of capabilities is a subset of the default list.

If the specified capabilities are not in the default set, container engines should print an error message and will run the container with the default capabilities. ๐Ÿ’€

  • --layer-label label[=value] โ€” add an intermediate image label (e.g. label=value) to the metadata in intermediate images, i.e., any images built for non-final stages and for non-final instructions in stages when --layers is true. It can be used multiple times. If label is named, but neither = nor a value is provided, then the label is set to an empty value. ๐ŸŽ€
  • --layers bool-value โ€” cache intermediate images during the build process (Default is false).
๐Ÿ’ก Note: You can also override the default value of layers by setting the BUILDAH_LAYERS environment variable. Like: export BUILDAH_LAYERS=true
  • --logfile filename โ€” log output which would be sent to standard output and standard error to the specified file instead of to standard output and standard error. bye stdout, hello file ๐Ÿฆ‹
  • --logsplit bool-value โ€” if --logfile and --platform is specified following flag allows end-users to split log file for each platform into different files with naming convention as ${logfile}_${platform-os}_${platform-arch}. one log per platform, no cap ๐Ÿ“โœจ
  • --manifest listName โ€” name of the manifest list to which the built image will be added. Creates the manifest list if it does not exist. This option is useful for building multi architecture images. If listName does not include a registry name component, the registry name localhost will be prepended to the list name. ๐ŸŒˆ
  • --memory, -m="" โ€” memory limit (format: [], where unit = b, k, m or g)

Allows you to constrain the memory available to a container. If the host supports swap memory, then the -m memory setting can be larger than physical RAM. If a limit of 0 is specified (not using -m), the container's memory is not limited. The actual limit may be rounded up to a multiple of the operating system's page size (the value would be very large, that's millions of trillions). ๐Ÿ˜ญ that number is not real, bestie

  • --memory-swap="LIMIT" โ€” this sets the total of memory plus swap, bestie. ๐Ÿ’œ It only works if you also pass -m (--memory), and the swap LIMIT should always be bigger than the -m (--memory) value. No worries though โ€” by default the swap LIMIT just gets set to double whatever --memory is. Iconic.

The format of LIMIT is <number>[<unit>]. Unit can be b (bytes), k (kilobytes), m (megabytes), or g (gigabytes). If you don't specify a unit, b is used. Set LIMIT to -1 to enable unlimited swap.

  • --metadata-file MetadataFile โ€” writes all the info about the built image into the file you name. ๐ŸŽ€ Heads up though: when --platform is specified more than once, trying to use this option will trigger an error. So pick one, diva.
  • --mount mount-instruction โ€” adds this mount to each RUN command in a Containerfile before executing it. Fr fr, every single one. For example:
buildah build --mount type=secret,id=mysecret ...

and a Containerfile entry of:

RUN cat /run/secrets/mysecret

has the same effect as:

RUN --mount=type=secret,id=mysecret cat /run/secrets/mysecret
  • --network, --net=mode โ€” sets the config for network namespaces when handling RUN instructions. ๐ŸŒˆ

Valid mode values are:

  • none: no networking. Invalid if using --dns, --dns-option, or --dns-search.
  • host: use the host network stack. Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure.
  • ns:path: path to a network namespace to join.
  • private: create a new namespace for the container (default).
  • <network name|ID>: join the network with the given name or ID, e.g. use --network mynet to join the network with the name mynet. Only supported for rootful users.
  • pasta[:OPTIONS,...]: use pasta(1) to create a user-mode networking stack. This is only supported in rootless mode. By default, IPv4 and IPv6 addresses and routes, as well as the pod interface name, are copied from the host. If port forwarding isn't configured, ports are forwarded dynamically as services are bound on either side (init namespace or container namespace). Port forwarding preserves the original source IP address. Options described in pasta(1) can be specified as comma-separated arguments. In terms of pasta(1) options, --config-net is given by default, in order to configure networking when the container is started, and --no-map-gw is also assumed by default, to avoid direct access from container to host using the gateway address. The latter can be overridden by passing --map-gw in the pasta-specific options (despite not being an actual pasta(1) option). Also, -t none and -u none are passed to disable automatic port forwarding based on bound ports. Similarly, -T none and -U none are given to disable the same functionality from container to host. Some examples:
    • pasta:--map-gw: allow the container to directly reach the host using the gateway address.
    • pasta:--mtu,1500: specify a 1500 bytes MTU for the tap interface in the container.
    • pasta:--ipv4-only,-a,10.0.2.0,-n,24,-g,10.0.2.2,--dns-forward,10.0.2.3,-m,1500,--no-ndp,--no-dhcpv6,--no-dhcp: disable IPv6, assign 10.0.2.0/24 to the tap0 interface in the container, with gateway 10.0.2.3, enable DNS forwarder reachable at 10.0.2.3, set MTU to 1500 bytes, disable NDP, DHCPv6 and DHCP support.
    • pasta:-I,tap0,--ipv4-only,-a,10.0.2.0,-n,24,-g,10.0.2.2,--dns-forward,10.0.2.3,--no-ndp,--no-dhcpv6,--no-dhcp: same as above, but leave the MTU to 65520 bytes.
    • pasta:-t,auto,-u,auto,-T,auto,-U,auto: enable automatic port forwarding based on observed bound ports from both host and container sides.
    • pasta:-T,5201: enable forwarding of TCP port 5201 from container to host, using the loopback interface instead of the tap interface for improved performance.
  • --no-cache โ€” do not use existing cached images for the container build. ๐Ÿซถ Start fresh from the beginning with a brand new set of cached layers. Clean slate era.
  • --no-hostname โ€” do not create the /etc/hostname file in the container for RUN instructions.

By default, Buildah manages the /etc/hostname file, adding the container's own hostname. When the --no-hostname option is set, the image's /etc/hostname will be preserved unmodified if it exists. Leave her alone, she's fine. ๐Ÿ’…

  • --no-hosts โ€” do not create the /etc/hosts file in the container for RUN instructions.

By default, Buildah manages /etc/hosts, adding the container's own IP address. --no-hosts disables this, and the image's /etc/hosts will be preserved unmodified. Conflicts with the --add-host option. Pick a side, bestie. โš”๏ธ

  • --omit-history bool-value โ€” omit build history information in the built image (default false).

This option is useful for the cases where end users explicitly want to set --omit-history to omit the optional History from built images, or when working with images built using build tools that do not include History information in their images.

  • --os="OS" โ€” set the OS of the image to be built, and that of the base image to be pulled, if the build uses one, instead of using the current operating system of the host. ๐ŸŒธ
  • --os-feature feature โ€” set the name of a required operating system feature for the image which will be built. By default, if the image is not based on scratch, the base image's required OS feature list is kept, if the base image specified any. This option is typically only meaningful when the image's OS is Windows.

If feature has a trailing -, then the feature is removed from the set of required features which will be listed in the image. Subtracting features, we love to see it. โœจ

  • --os-version version โ€” set the exact required operating system version for the image which will be built. By default, if the image is not based on scratch, the base image's required OS version is kept, if the base image specified one. This option is typically only meaningful when the image's OS is Windows, and is typically set in Windows base images, so using this option is usually unnecessary. Ngl you probs won't need it. ๐Ÿฆ‹
  • --output, -o="" โ€” additional output (format: type=local,dest=path).

The --output (or -o) option supplements the default behavior of building a container image by allowing users to export the image's contents as files on the local filesystem, which can be useful for generating local binaries, code generation, etc. ๐ŸŽ€

The value for --output is a comma-separated sequence of key=value pairs, defining the output type and options.

Supported keys are:

  • dest: destination for exported output. Can be set to - to indicate standard output, or to an absolute or relative path.
  • type: defines the type of output to be written. Must be one of the values listed below.

Valid type values are:

  • local: write the resulting build files to a directory on the client-side.
  • tar: write the resulting files as a single tarball (.tar).

Alternatively, instead of a comma-separated sequence, the value of --output can be just the destination (in the dest format) (e.g. --output some-path, --output -), and the type will be inferred to be tar if the output destination is -, and local otherwise.

Timestamps on the output contents will be set to exactly match the value specified using the --timestamp flag, or to exactly match the value specified for the --source-date-epoch flag, if either are specified. โฐ

Note that the --tag option can also be used to write the image to any location described by containers-transports(5).

  • --pid how โ€” sets the configuration for PID namespaces when handling RUN instructions. The configured value can be "" (the empty string) or "private" to indicate that a new PID namespace should be created, or it can be "host" to indicate that the PID namespace in which buildah itself is being run should be reused, or it can be the path to a PID namespace which is already in use by another process. ๐Ÿงš
  • --platform="OS/ARCH[/VARIANT]" โ€” set the OS/ARCH of the built image (and its base image, if your build uses one) to the provided value instead of using the current operating system and architecture of the host (for example linux/arm, linux/arm64, linux/amd64). ๐Ÿ”ฅ

The --platform flag can be specified more than once, or given a comma-separated list of values as its argument. When more than one platform is specified, the --manifest option should be used instead of the --tag option.

OS/ARCH pairs are those used by the Go Programming Language. In several cases the ARCH value for a platform differs from one produced by other tools such as the arch command. Valid OS and architecture name combinations are listed as values for $GOOS and $GOARCH at https://golang.org/doc/install/source#environment, and can also be found by running go tool dist list.

The buildah build command allows building images for all Linux architectures, even non-native architectures. When building images for a different architecture, the RUN instructions require emulation software installed on the host provided by packages like qemu-user-static. Note: it is always preferred to build images on the native architecture if possible. ๐Ÿ’€

NOTE: The --platform option may not be used in combination with the --arch, --os, or --variant options.
  • --pull โ€” pull image policy. If not specified, the default is missing. If an explicit --pull argument is provided without any value, use the always behavior. ๐Ÿ‘‘
    • always: pull base and SBOM scanner images from the registries listed in registries.conf. Raise an error if a base or SBOM scanner image is not found in the registries, even if an image with the same name is present locally.
    • missing: SBOM scanner images only if they could not be found in the local containers storage. Raise an error if no image could be found and the pull fails.
    • never: do not pull base and SBOM scanner images from registries, use only the local versions. Raise an error if the image is not present locally.
    • newer: pull base and SBOM scanner images from the registries listed in registries.conf if newer. Raise an error if a base or SBOM scanner image is not found in the registries when image with the same name is not present locally.
  • --quiet, -q โ€” suppress output messages which indicate which instruction is being processed, and of progress when pulling images from a registry, and when writing the output image. Silence, bestie. ๐Ÿคซ
  • --retry attempts

Number of times to retry in case of failure when performing push/pull of images to/from registry. Defaults to 3. three lil attempts before we accept the vibe check failed, bestie.

  • --retry-delay duration โ€” Duration of delay between retry attempts in case of failure when performing push/pull of images to/from registry. Defaults to 2s. so we wait, then we try again โ€” no chaotic spam energy.
  • --rewrite-timestamp โ€” When generating new layers for the image, ensure that no newly added content bears a timestamp later than the value used by the --source-date-epoch flag, if one was provided, by replacing any timestamps which are later than that value, with that value. basically: no sneaky future timestamps, they get snapped back to the cap you set.
  • --rm bool-value โ€” Remove intermediate containers after a successful build (default true). successful build? bye intermediate containers, love that for us.
  • --runtime path โ€” The path to an alternate OCI-compatible runtime, which will be used to run commands specified by the RUN instruction. Default is runc, or crun when machine is configured to use cgroups V2.
Note: You can also override the default runtime by setting the BUILDAH_RUNTIME environment variable. export BUILDAH_RUNTIME=/usr/bin/crun
  • --runtime-flag flag โ€” Adds global flags for the container runtime. To list the supported flags, please consult the manpages of the selected container runtime.
Note: Do not pass the leading -- to the flag. To pass the runc flag --log-format json to buildah build, the option given would be --runtime-flag log-format=json.
  • --save-stages bool-value โ€” Preserve intermediate stage images instead of removing them after the build completes (Default is false). By default, Buildah removes intermediate stage images to save space. This option keeps those images, which can be useful for debugging multi-stage builds or for reusing intermediate stages in subsequent builds.

--save-stages can be used with --layers and subsequent builds with --layers can use the preserved intermediate layers as cache.

When combined with --stage-labels, all stage images (including the final image) will include metadata labels for easier identification and management.

  • --sbom preset โ€” Generate SBOMs (Software Bills Of Materials) for the output image by scanning the working container and build contexts using the named combination of scanner image, scanner commands, and merge strategy. Must be specified with one or more of --sbom-image-output, --sbom-image-purl-output, --sbom-output, and --sbom-purl-output. Recognized presets, and the set of options which they equate to:
    • "syft", "syft-cyclonedx":
--sbom-scanner-image=ghcr.io/anchore/syft
--sbom-scanner-command="/syft scan -q dir:{ROOTFS} --output cyclonedx-json={OUTPUT}"
--sbom-scanner-command="/syft scan -q dir:{CONTEXT} --output cyclonedx-json={OUTPUT}"
--sbom-merge-strategy=merge-cyclonedx-by-component-name-and-version
  • "syft-spdx":
--sbom-scanner-image=ghcr.io/anchore/syft
--sbom-scanner-command="/syft scan -q dir:{ROOTFS} --output spdx-json={OUTPUT}"
--sbom-scanner-command="/syft scan -q dir:{CONTEXT} --output spdx-json={OUTPUT}"
--sbom-merge-strategy=merge-spdx-by-package-name-and-versioninfo
  • "trivy", "trivy-cyclonedx":
--sbom-scanner-image=ghcr.io/aquasecurity/trivy
--sbom-scanner-command="trivy filesystem -q {ROOTFS} --format cyclonedx --output {OUTPUT}"
--sbom-scanner-command="trivy filesystem -q {CONTEXT} --format cyclonedx --output {OUTPUT}"
--sbom-merge-strategy=merge-cyclonedx-by-component-name-and-version
  • "trivy-spdx":
--sbom-scanner-image=ghcr.io/aquasecurity/trivy
--sbom-scanner-command="trivy filesystem -q {ROOTFS} --format spdx-json --output {OUTPUT}"
--sbom-scanner-command="trivy filesystem -q {CONTEXT} --format spdx-json --output {OUTPUT}"
--sbom-merge-strategy=merge-spdx-by-package-name-and-versioninfo
  • --sbom-image-output path โ€” When generating SBOMs, store the generated SBOM in the specified path in the output image. There is no default. no default, bestie โ€” you gotta tell it where.
  • --sbom-image-purl-output path โ€” When generating SBOMs, scan them for PURL (package URL, https://github.com/package-url/purl-spec/blob/master/PURL-SPECIFICATION.rst) information, and save a list of found PURLs to the specified path in the output image. There is no default.
  • --sbom-merge-strategy method โ€” If more than one --sbom-scanner-command value is being used, use the specified method to merge the output from later commands with output from earlier commands. Recognized values include:
    • cat โ€” Concatenate the files.
    • merge-cyclonedx-by-component-name-and-version โ€” Merge the "component" fields of JSON documents, ignoring values from documents when the combination of their "name" and "version" values is already present. Documents are processed in the order in which they are generated, which is the order in which the commands that generate them were specified.
    • merge-spdx-by-package-name-and-versioninfo โ€” Merge the "package" fields of JSON documents, ignoring values from documents when the combination of their "name" and "versionInfo" values is already present. Documents are processed in the order in which they are generated, which is the order in which the commands that generate them were specified.
  • --sbom-output file โ€” When generating SBOMs, store the generated SBOM in the named file on the local filesystem. There is no default.
  • --sbom-purl-output file โ€” When generating SBOMs, scan them for PURL (package URL, https://github.com/package-url/purl-spec/blob/master/PURL-SPECIFICATION.rst) information, and save a list of found PURLs to the named file in the local filesystem. There is no default.
  • --sbom-scanner-command image โ€” Generate SBOMs by running the specified command from the scanner image. If multiple commands are specified, they are run in the order in which they are specified. These text substitutions are performed:
    • {ROOTFS} โ€” The root of the built image's filesystem, bind mounted.
    • {CONTEXT} โ€” The build context and additional build contexts, bind mounted.
    • {OUTPUT} โ€” The name of a temporary output file, to be read and merged with others or copied elsewhere.
  • --sbom-scanner-image image โ€” Generate SBOMs using the specified scanner image.
  • --secret=id=id[,src=envOrFile][,env=ENV][,type=file|env] โ€” Pass secret information to be used in the Containerfile for building images in a safe way that will not end up stored in the final image, or be seen in other stages. The value of the secret will be read from an environment variable or file named by the "id" option, or named by the "src" option if it is specified, or from an environment variable specified by the "env" option. The secret will be mounted in the container at /run/secrets/<id> by default.

To later use the secret, use the --mount flag in a RUN instruction within a Containerfile:

RUN --mount=type=secret,id=mysecret cat /run/secrets/mysecret

The location of the secret in the container can be overridden using the "target", "dst", or "destination" option of the RUN --mount flag.

RUN --mount=type=secret,id=mysecret,target=/run/secrets/myothersecret cat /run/secrets/myothersecret

The secret may alternatively be exposed as an environment variable to the process:

RUN --mount=type=secret,id=mysecret,env=FOO sh -c 'echo "Hello $FOO"'
Note: changing the contents of secret files will not trigger a rebuild of layers that use said secrets.
  • --security-opt=[] โ€” Security Options:
    • apparmor=unconfined โ€” Turn off apparmor confinement for the container.
    • apparmor=your-profile โ€” Set the apparmor confinement profile for the container.
    • label=user:USER โ€” Set the label user for the container.
    • label=role:ROLE โ€” Set the label role for the container.
    • label=type:TYPE โ€” Set the label type for the container.
    • label=level:LEVEL โ€” Set the label level for the container.
    • label=disable โ€” Turn off label confinement for the container.
    • mask=/path/1:/path/2 โ€” The paths to mask separated by a colon. A masked path cannot be accessed inside the container.
    • no-new-privileges โ€” Disable container processes from gaining additional privileges.
    • seccomp=unconfined โ€” Turn off seccomp confinement for the container.
    • seccomp=profile.json โ€” JSON configuration for a seccomp filter.
    • unmask=ALL or /path/1:/path/2, or shell expanded paths (/proc/*) โ€” Paths to unmask separated by a colon. If set to ALL, it unmasks all the paths that are masked or made read-only by default.

The default masked paths are /proc/acpi, /proc/interrupts, /proc/kcore, /proc/keys, /proc/latency_stats, /proc/sched_debug, /proc/scsi, /proc/timer_list, /proc/timer_stats, /sys/devices/virtual/powercap, /sys/firmware, and /sys/fs/selinux. The default paths that are read-only are /proc/asound, /proc/bus, /proc/fs, /proc/irq, /proc/sys, and /proc/sysrq-trigger.

  • --shm-size="" โ€” Size of /dev/shm. The format is <number><unit>. number must be greater than 0. Unit is optional and can be b (bytes), k (kilobytes), m (megabytes), or g (gigabytes). If you omit the unit, the system uses bytes. If you omit the size entirely, the system uses 64m.
  • --sign-by fingerprint โ€” Sign the built image using the GPG key that matches the specified fingerprint.
  • --skip-unused-stages bool-value โ€” Skip stages in multi-stage builds which don't affect the target stage. (Default is true). we love not building stuff nobody needs.
  • --source-date-epoch seconds โ€” Set the "created" timestamp for the built image to this number of seconds since the epoch (Unix time 0, i.e., 00:00:00 UTC on 1 January 1970) (default is to use the value set in the SOURCE_DATE_EPOCH environment variable, or the current time if it is not set).

The "created" timestamp is written into the image's configuration and manifest when the image is committed, so running the same build two different times will ordinarily produce images with different sha256 hashes, even if no other changes were made to the Containerfile and build context.

When this flag is set, a SOURCE_DATE_EPOCH build arg will provide its value for a stage in which it is declared.

When this flag is set, the image configuration's "created" timestamp is always set to the time specified, which should allow for identical images to be built at different times using the same set of inputs. reproducible build main character energy, periodt โœจ

...so when that flag's set, whatever gets written out via --output carries <em>exactly</em> that timestamp. no slush, no drift. โœจ

Heads up though: it conflicts with the similar --timestamp flag โ€” bc --timestamp also stamps its time onto the contents of new layers. can't have both doing their thing, bestie. ๐Ÿ’…

  • --source-policy-file pathname โ€” gives you the path to a BuildKit-compatible source policy JSON file ๐Ÿ“œ. once it's set, source references (think base images in FROM instructions) get evaluated against the policy rules before anyone uses them.

like, source policies let you control which images are even allowed to be base images, and optionally convert image references (pinning tags to specific digests, say) โ€” all without touching your Containerfiles. which is giving very much organizational-policy-enforcement and build-reproducibility energy ๐ŸŽ€.

the policy file is a JSON doc with an array of rules. every rule has:

  • action: what happens when the rule matches. the valid actions are:
    • ALLOW: explicitly allow the source (no transformation).
    • DENY: block the source and fail the build ๐Ÿ’€.
    • CONVERT: transform the source to a different reference specified in updates.
  • selector: says which sources the rule applies to.
    • identifier: the source identifier to match (e.g. docker-image://docker.io/library/alpine:latest).
    • matchType: how to match the identifier. valid types are EXACT and WILDCARD (supports * and ? glob patterns). defaults to WILDCARD if you don't specify.
  • updates: for CONVERT actions, this specifies the replacement identifier.

rules get evaluated in order and the first matching rule wins. if literally no rule matches, the source is allowed by default. chill of it.

Note: source policy CONVERT rules get processed after --build-context substitutions but before any substitutions specified in containers-registries.conf(5). so you've got multiple ways to override which base image a particular stage uses, in order of precedence: --build-context, then source policy, then registries.conf. iykyk ๐Ÿ”ฅ

here's an example policy file that pins alpine:latest to a specific digest:

{
  "rules": [
    {
      "action": "CONVERT",
      "selector": {
        "identifier": "docker-image://docker.io/library/alpine:latest"
      },
      "updates": {
        "identifier": "docker-image://docker.io/library/alpine@sha256:..."
      }
    }
  ]
}

and here's one that denies all ubuntu images, absolute icon behaviour:

{
  "rules": [
    {
      "action": "DENY",
      "selector": {
        "identifier": "docker-image://docker.io/library/ubuntu:*",
        "matchType": "WILDCARD"
      }
    }
  ]
}
  • --squash โ€” squashes all the layers into one single layer, including the ones from your base image(s). (default is false.) ๐Ÿซถ

ok so by default Buildah keeps the existing base-image layers and adds just one new layer per build. and --layers is the flag for preserving intermediate build layers. different vibe, don't mix them up ๐Ÿ’–

  • --ssh=default|id[=socket>|[,] โ€” the SSH agent socket or keys you wanna expose to the build. you can leave the socket path empty to use the value of default=$SSH_AUTH_SOCK ๐Ÿ”‘

to actually use the ssh agent later, hit up the --mount flag in a RUN instruction inside your Containerfile:

RUN --mount=type=secret,id=id mycmd
NOTE: when you're running as a non-default root user, you gotta specify either mode, uid or gid options along with the mount options. like, here's how you make the ssh socket available to an app user with uid=50000:
# Switch to application user (Note that uid depends on container image)
USER app
# ...and check whether ssh identities are available
RUN --mount=type=ssh,uid=50000
    ssh-add -L
  • --stage-labels bool-value โ€” slaps metadata labels onto all the intermediate stage images of your multistage build, final image included (default is false). but bestie, this one requires --save-stages to be enabled or it's not happening ๐ŸŽ€

when it's on, all intermediate stage images and the final image get labeled with:

  • io.buildah.stage.name: the stage alias (from FROM ... AS alias), or the stage position if no alias is specified
  • io.buildah.stage.base: the base image this stage uses (pullspec or image ID when the stage uses another stage as base)

these labels are lowkey the whole point โ€” they make it way easier to identify, query and manage images from multi-stage builds ๐Ÿ‘‘

  • --stdin โ€” passes stdin into the RUN containers. sometimes commands being RUN inside a Containerfile wanna ask the user stuff. think apt asking you to confirm an install ๐Ÿ™ˆ. use --stdin so you can actually interact from the terminal during the build.
  • --tag, -t imageName โ€” sets the name assigned to the resulting image if the build completes successfully ๐ŸŽ‰. if imageName doesn't include a registry name component, the registry name localhost gets prepended to the image name. yes, automatically, no you don't get a say.

--tag supports all transports from containers-transports(5). if no transport is specified, the containers-storage (i.e., local storage) transport is used.

buildah build --tag=oci-archive:./foo.ociarchive .
buildah build -t quay.io/username/foo  .
  • --target stageName โ€” sets the target build stage to build ๐ŸŽฏ. when you're building a Containerfile with multiple build stages, --target lets you name an intermediate build stage as the final stage for the resulting image. anything after the target stage gets skipped, periodt.
  • --timestamp seconds โ€” sets the "created" timestamp for the built image to this many seconds since the epoch (Unix time 0, i.e., 00:00:00 UTC on 1 January 1970) (defaults to current time) โฐ

the "created" timestamp gets written into the image's configuration and manifest when the image is committed, so running the same build twice at different times will ordinarily produce images with different sha256 hashes โ€” even if literally nothing else changed in the Containerfile or build context. annoying but true ๐Ÿ˜ญ

when --timestamp is set, the "created" timestamp is always set to the time you specified, which should let identical images get built at different times from the same set of inputs. reproducibility slay โœจ

when --timestamp is set, all content in layers created as part of the build โ€” and output written as specified to the --output flag โ€” will also bear this same timestamp.

it conflicts with the similar --source-date-epoch flag, which by default does not affect the timestamps of layer contents. pick a lane ๐Ÿ’…

  • --tls-verify bool-value โ€” requires HTTPS and certificate verification when talking to container registries (defaults to true) and when retrieving content from HTTPS locations for ADD instructions ๐Ÿ”’. and nope, TLS verification cannot be used when talking to an insecure registry. safety first but also rules are rules.
  • --ulimit type=soft-limit[:hard-limit] โ€” specifies resource limits to apply to processes launched when processing RUN instructions. you can specify this option multiple times, stack 'em up ๐Ÿงš. recognized resource types include:
    • "core": maximum core dump size (ulimit -c)
    • "cpu": maximum CPU time (ulimit -t)
    • "data": maximum size of a process's data segment (ulimit -d)
    • "fsize": maximum size of new files (ulimit -f)
    • "locks": maximum number of file locks (ulimit -x)
    • "memlock": maximum amount of locked memory (ulimit -l)
    • "msgqueue": maximum amount of data in message queues (ulimit -q)
    • "nice": niceness adjustment (nice -n, ulimit -e)
    • "nofile": maximum number of open files (ulimit -n)
    • "nofile": maximum number of open files (1048576); when run by root
    • "nproc": maximum number of processes (ulimit -u)
    • "nproc": maximum number of processes (1048576); when run by root
    • "rss": maximum size of a process's (ulimit -m)
    • "rtprio": maximum real-time scheduling priority (ulimit -r)
    • "rttime": maximum amount of real-time execution between blocking syscalls
    • "sigpending": maximum number of pending signals (ulimit -i)
    • "stack": maximum stack size (ulimit -s)
  • --unsetannotation annotation โ€” unsets the image annotation, so it does not get inherited from the base image ๐Ÿšซ. bye felicia.
  • --unsetenv env โ€” unsets environment variables from the final image ๐ŸŒธ
  • --unsetlabel label โ€” unsets the image label, so it does not get inherited from the base image. same energy, different field ๐ŸŽ€
  • --userns how โ€” sets the config for user namespaces when handling RUN instructions. the value can be "" (the empty string), "private" or "auto" to say a new user namespace should be created, it can be "host" to say the user namespace buildah itself is being run in should be reused, or it can be a path to a user namespace that's already in use by another process ๐Ÿ‘‘

auto: automatically creates a unique user namespace ๐Ÿฆ‹

the --userns=auto flag requires that the user name containers and a range of subordinate user ids that the build container is allowed to use be specified in the /etc/subuid and /etc/subgid files.

Example: containers:2147483647:2147483648.

Buildah allocates unique ranges of UIDs and GIDs from the containers subordinate user ids. the size of the ranges is based on the number of UIDs required in the image. and psst โ€” the number of UIDs and GIDs can be overridden with the size option โœจ

valid auto options:

  • gidmapping=CONTAINER_GID:HOST_GID:SIZE: to force a GID mapping to be present in the user namespace.
  • size=SIZE: to specify an explicit size for the automatic user namespace. e.g. --userns=auto:size=8192. if size is not specified, auto will estimate a size for the user namespace.
  • uidmapping=CONTAINER_UID:HOST_UID:SIZE: to force a UID mapping to be present in the user namespace.
  • --userns-gid-map mapping โ€” directly specifies a GID mapping to be used to set ownership, at the filesystem level, on the working container's contents ๐Ÿ—‚๏ธ. commands run when handling RUN instructions will default to being run in their own user namespaces, configured using the UID and GID maps.

entries in this map take the form of one or more colon-separated triples: a starting in-container GID, a corresponding starting host-level GID, and the number of consecutive IDs the map entry represents. trio of destiny ๐Ÿ’ซ

this option overrides the remap-gids setting in the options section of /etc/containers/storage.conf.

if this option isn't specified, but a global --userns-gid-map setting is supplied, settings from the global option get used instead.

  • --userns-gid-map-group group

Okay so for the --userns-gid-map-group girlies โ€” this tells buildah that the GID mapping you want (the one that sets ownership at the filesystem level on everything inside the working container) lives in the entries of /etc/subgid that match the group you name. When buildah handles RUN instructions, those commands default to running in their own user namespaces, configured with the UID and GID maps. And here's the cute shortcut: if you pass --userns-uid-map-user but don't pass --userns-gid-map-group, buildah just assumes the user name you gave is also a totally suitable group name to use as the default for this option. ๐Ÿ’ซ

You can also skip all that and specify the maps directly with --userns-gid-map, which is described over in the buildah(1) man page.

NOTE: if a rootless user sets this option, the mappings are relative to the rootless usernamespace in the container, not relative to the host like they'd be when run rootful. Different frame of reference, bestie โ€” don't mix them up. ๐Ÿ™ˆ

--userns-uid-map mapping

This one directly specifies a UID mapping to set ownership, at the filesystem level, on the working container's contents. Commands run when handling RUN instructions default to running in their own user namespaces, configured using the UID and GID maps. โœจ

The entries in this map look like one or more colon-separated triples: a starting in-container UID, a corresponding starting host-level UID, and the number of consecutive IDs that map entry covers.

This option overrides the remap-uids setting in the options section of /etc/containers/storage.conf.

If you don't specify this option but you do supply a global --userns-uid-map setting, then the global one wins and its settings get used. ๐Ÿซถ

--userns-uid-map-user user

Specifies that the UID mapping used to set ownership, at the filesystem level, on the working container's contents can be found in the entries of /etc/subuid that correspond to the user you name. Commands run when handling RUN instructions default to running in their own user namespaces, configured using the UID and GID maps. And the mirror-image shortcut: if --userns-gid-map-group is specified but --userns-uid-map-user isn't, buildah assumes the group name you gave is also a suitable user name to use as the default here. ๐Ÿ’…

NOTE: when a rootless user specifies this option, the mappings are relative to the rootless usernamespace in the container, not relative to the host as they'd be when run rootful.

--uts how

Sets the configuration for UTS namespaces when handling RUN instructions. The value can be "" (the empty string) or "container" to say "make a brand new UTS namespace please", or "host" to say "just reuse the UTS namespace buildah itself is running in", or it can be the path to a UTS namespace that's already in use by another process. โœจ

--variant=""

Set the architecture variant of the image to be pulled. ๐ŸŽ€

--volume, -v[=[HOST-DIR:CONTAINER-DIR[:OPTIONS]]]

Mounts a host directory into containers when executing RUN instructions during the build. The OPTIONS are a comma-delimited list, and they can be:

  • [rw|ro]
  • [U]
  • [z|Z|O]
  • [[r]shared|[r]slave|[r]private] [1]

The CONTAINER-DIR has to be an absolute path like /src/docs. The HOST-DIR has to be an absolute path too. Buildah bind-mounts the HOST-DIR to the path you specify. So like, if you supply /foo as the host path, Buildah copies the contents of /foo to the container filesystem on the host and bind mounts that into the container.

You can specify multiple -v options to mount one or more mounts to a container. Slay. ๐Ÿ’–

Write Protected Volume Mounts

Add the :ro or :rw suffix to a volume to mount it read-only or read-write respectively. By default, volumes are mounted read-write. See the examples. ๐Ÿ‘€

Chowning Volume Mounts

By default, Buildah does not change the owner and group of source volume directories mounted into containers. If a container is created in a new user namespace, the UID and GID in the container may correspond to a different UID and GID on the host.

The :U suffix tells Buildah to use the correct host UID and GID based on the UID and GID within the container, to change the owner and group of the source volume. ๐Ÿซถ

Labeling Volume Mounts

Labeling systems like SELinux need proper labels on volume content mounted into a container. Without a label, the security system might stop the processes running inside the container from using that content. By default, Buildah doesn't change the labels set by the OS.

To change a label in the container context, add either of the two suffixes :z or :Z to the volume mount. These tell Buildah to relabel file objects on the shared volumes:

  • The z option tells Buildah that two containers share the volume content. So Buildah labels the content with a shared content label. Shared volume labels let all containers read/write the content.
  • The Z option tells Buildah to label the content with a private unshared label. Only the current container can use a private volume.

Overlay Volume Mounts

The :O flag tells Buildah to mount the directory from the host as temporary storage using the Overlay file system. The RUN command containers are allowed to modify contents within the mountpoint, and those changes get stored in the container storage in a separate directory. In Overlay FS terms, the source directory is the lower, and the container storage directory is the upper. Modifications to the mount point are destroyed when the RUN command finishes executing โ€” very tmpfs mount point of them. ๐Ÿ’€

Any subsequent execution of RUN commands sees the original source directory content; any changes from previous RUN commands no longer exist.

One use case for the overlay mount is sharing the package cache from the host into the container to speed up builds. Obsessed, honestly. ๐Ÿ”ฅ

Note:

  • The O flag is not allowed to be specified with the Z or z flags. Content mounted into the container is labeled with the private label. On SELinux systems, labels in the source directory must be readable by the container label. If they're not, SELinux container separation must be disabled for the container to work.
  • Modification of the directory volume mounted into the container with an overlay mount can cause unexpected failures. It's recommended that you don't modify the directory until the container finishes running. ๐Ÿ™

By default, bind mounted volumes are private. That means any mounts done inside the container won't be visible on the host, and vice versa. You can change this behavior by specifying a volume mount propagation property.

When the mount propagation policy is set to shared, any mounts completed inside the container on that volume will be visible to both the host and the container. When it's set to slave, one-way mount propagation is enabled and any mounts completed on the host for that volume will be visible only inside the container. To control the mount propagation property of the volume, use the :[r]shared, :[r]slave or :[r]private propagation flag. The propagation property can be specified only for bind mounted volumes โ€” not for internal volumes or named volumes. For mount propagation to work on the source mount point (the mount point where the source dir is mounted on), it has to have the right propagation properties. For shared volumes, the source mount point has to be shared. For slave volumes, the source mount has to be either shared or slave. [1]

Use df <source-dir> to determine the source mount, then use findmnt -o TARGET,PROPAGATION <source-mount-dir> to determine the propagation properties of the source mount. If the findmnt utility isn't available, the source mount point can be determined by looking at the mount entry in /proc/self/mountinfo. Look at the optional fields and see if any propagation properties are specified. shared:X means the mount is shared, master:X means the mount is slave, and if there's nothing there, that means the mount is private. [1] ๐Ÿ•ต๏ธ

To change the propagation properties of a mount point, use the mount command. For example, to bind mount the source directory /foo, do mount --bind /foo /foo and mount --make-private --make-shared /foo. This converts /foo into a shared mount point. The propagation properties of the source mount can be changed directly โ€” for instance, if / is the source mount for /foo, then use mount --make-shared / to convert / into a shared mount. โœจ


๐ŸŒˆ BUILD TIME VARIABLES ๐ŸŒˆ

The ENV instruction in a Containerfile can define variable values. When the image is built, those values persist in the container image. But sometimes it's way more convenient to change the values in the Containerfile via a command-line option instead of editing the values inside the Containerfile itself. Iconic behavior, honestly. ๐Ÿ’…

These variables can be used together with the --build-arg option to override the corresponding values set in the Containerfile using the ENV instruction:

  • HTTP_PROXY
  • HTTPS_PROXY
  • FTP_PROXY
  • NO_PROXY

Please refer to the Using Build Time Variables section of the Examples. ๐Ÿซถ

๐Ÿ’… EXAMPLE ๐Ÿ’…

okay bestie, this is the part where the manpage stops explaining and starts showing โ€” screenshot energy, fr fr. All commands are copied exactly, so you can steal them straight into your terminal. ๐Ÿ“ธโœจ

๐Ÿ› ๏ธ Build an image using local Containerfiles ๐Ÿ› ๏ธ

Hereโ€™s the whole lineup of local-Containerfile examples. no cap, this is the good stuff:

buildah build .

buildah build -f Containerfile .

cat ~/Containerfile | buildah build -f - .

buildah build -f Containerfile.simple -f Containerfile.notsosimple .

buildah build --timestamp=$(date '+%s') -t imageName .

buildah build -t imageName .

buildah build --tls-verify=true -t imageName -f Containerfile.simple .

buildah build --tls-verify=false -t imageName .

buildah build --runtime-flag log-format=json .

buildah build -f Containerfile --runtime-flag debug .

buildah build --authfile /tmp/auths/myauths.json --cert-dir ~/auth --tls-verify=true --creds=username:password -t imageName -f Containerfile.simple .

buildah build --memory 40m --cpu-period 10000 --cpu-quota 50000 --ulimit nofile=1024:1028 -t imageName .

buildah build --security-opt label=level:s0:c100,c200 --cgroup-parent /path/to/cgroup/parent -t imageName .

buildah build --arch=arm --variant v7 -t imageName .

buildah build --volume /home/test:/myvol:ro,Z -t imageName .

buildah build -v /home/test:/myvol:z,U -t imageName .

buildah build -v /var/lib/dnf:/var/lib/dnf:O -t imageName .

buildah build --layers -t imageName .

buildah build --save-stages -t imageName .

buildah build --save-stages --layers -t imageName .

buildah build --save-stages --stage-labels -t imageName .

buildah build --save-stages --stage-labels --layers -t imageName .

buildah build --no-cache -t imageName .

buildah build -f Containerfile --layers --force-rm -t imageName .

buildah build --no-cache --rm=false -t imageName .

buildah build --dns-search=example.com --dns=223.5.5.5 --dns-option=use-vc .

buildah build -f Containerfile.in --cpp-flag="-DDEBUG" -t imageName .

buildah build --network mynet .

buildah build --env LANG=en_US.UTF-8 -t imageName .

buildah build --env EDITOR -t imageName .

buildah build --unsetenv LANG -t imageName .

buildah build --os-version 10.0.19042.1645 -t imageName .

buildah build --os-feature win32k -t imageName .

buildah build --os-feature win32k- -t imageName .

buildah build --secret=id=mysecret .

buildah build --secret=id=mysecret,env=MYSECRET .

buildah build --secret=id=mysecret,src=MYSECRET,type=env .

buildah build --secret=id=mysecret,src=.mysecret,type=file .

buildah build --secret=id=mysecret,src=.mysecret .

๐Ÿ“œ Building an image with a source policy ๐Ÿ“œ

Source policy file? say less. ๐Ÿซถ

buildah build --source-policy-file /etc/buildah/source-policy.json -t imageName .

๐Ÿ”— Using FROM --after for explicit stage dependencies ๐Ÿ”—

okay so this one matters: when youโ€™re using local transports like FROM oci-archive:file.ociarchive where the file is produced by an earlier stage, Buildah cannot automatically detect the dependency. Use the --after flag on the FROM instruction to declare explicit stage dependencies:

FROM quay.io/skopeo/stable AS builder
RUN --mount=type=bind,target=/src,rw skopeo copy docker://quay.io/fedora/fedora-minimal oci-archive:/src/fedora.ociarchive

FROM --after=builder oci-archive:fedora.ociarchive
# This stage will wait for builder to complete before evaluating FROM

๐ŸŒˆ Building an multi-architecture image using the --manifest option (requires emulation software) ๐ŸŒˆ

mult-arch era, literally. ๐Ÿ’…

buildah build --arch arm --manifest myimage /tmp/mysrc

buildah build --arch amd64 --manifest myimage /tmp/mysrc

buildah build --arch s390x --manifest myimage /tmp/mysrc

buildah bud --platform linux/s390x,linux/ppc64le,linux/amd64 --manifest myimage /tmp/mysrc

buildah build --platform linux/arm64 --platform linux/amd64 --manifest myimage /tmp/mysrc

buildah bud --all-platforms --manifest myimage /tmp/mysrc

๐ŸŽ Building an image using (--output) custom build output ๐ŸŽ

custom output is giving main character energy, ngl:

buildah build -o out .

buildah build --output type=local,dest=out .

buildah build --output type=tar,dest=out.tar .

buildah build -o - . > out.tar

๐Ÿท๏ธ Preserving and querying intermediate stage images ๐Ÿท๏ธ

Build a multi-stage image while preserving intermediate stages with metadata labels:

buildah build --save-stages --stage-labels -t myapp .

Find an intermediate image for a specific stage name:

buildah images --filter "label=io.buildah.stage.name=builder"

Find an intermediate image for a specific stage base image:

buildah images --filter "label=io.buildah.stage.base=golang:1.21"

๐ŸŒ Building an image using a URL ๐ŸŒ

This will clone the specified GitHub repository from the URL and use it as context. The Containerfile or Dockerfile at the root of the repository is used as the context of the build. This only works if the GitHub repository is a dedicated repository.

buildah build https://github.com/containers/PodmanHello.git
Note: Github does not support using git:// for performing clone operation due to recent changes in their security guidance (https://github.blog/2021-09-01-improving-git-protocol-security-github/). Use an https:// URL if the source repository is hosted on Github.

๐Ÿ“ฆ Building an image using a URL to a tarball'ed context ๐Ÿ“ฆ

Buildah will fetch the tarball archive, decompress it and use its contents as the build context. The Containerfile or Dockerfile at the root of the archive and the rest of the archive will get used as the context of the build. If you pass an -f PATH/Containerfile option as well, the system will look for that file inside the contents of the tarball.

buildah build -f dev/Containerfile https://10.10.10.1/buildah/context.tar.gz
Note: supported compression formats are xz, bzip2, gzip and identity (no compression).

๐Ÿงช Using Build Time Variables ๐Ÿงช

Replace the value set for the HTTP_PROXY environment variable within the Containerfile.

buildah build --build-arg=HTTP_PROXY="http://127.0.0.1:8321"

๐ŸŒฟ ENVIRONMENT ๐ŸŒฟ

okay bestie, env vars are lowkey the backstage pass of this whole thing. ๐ŸŽŸ๏ธ

  • BUILD_REGISTRY_SOURCES โ€” BUILD_REGISTRY_SOURCES, if set, is treated as a JSON object which contains lists of registry names under the keys insecureRegistries, blockedRegistries, and allowedRegistries.

When pulling an image from a registry, if the name of the registry matches any of the items in the blockedRegistries list, the image pull attempt is denied. If there are registries in the allowedRegistries list, and the registryโ€™s name is not in the list, the pull attempt is denied.

  • TMPDIR โ€” The TMPDIR environment variable allows the user to specify where temporary files are stored while pulling and pushing images. Defaults to /var/tmp.

๐Ÿ“ Files ๐Ÿ“

๐Ÿšซ .containerignore/.dockerignore ๐Ÿšซ

If the .containerignore/.dockerignore file exists in the context directory, buildah build reads its contents. If both exist, then .containerignore is used. Use the --ignorefile flag to override the ignore file path location. Buildah uses the content to exclude files and directories from the context directory, when executing COPY and ADD directives in the Containerfile/Dockerfile. COPY and ADD also support --exclude; patterns are relative to the copy source.

Users can specify a series of Unix shell globals in a .containerignore/.dockerignore file to identify files/directories to exclude.

Buildah supports a special wildcard string ** which matches any number of directories (including zero). For example, **/*.go will exclude all files that end with .go that are found in all directories.

Example .containerignore file:

# exclude this content for image
*/*.c
**/output*
src

*/*.c Excludes files and directories whose names end with .c in any top level subdirectory. For example, the source file include/rootless.c.

**/output* Excludes files and directories starting with output from any directory.

src Excludes files named src and the directory src as well as any content in it.

Lines starting with ! (exclamation mark) can be used to make exceptions to exclusions. The following is an example .containerignore/.dockerignore file that uses this mechanism:

*.doc
!Help.doc

Exclude all doc files except Help.doc from the image.

This functionality is compatible with the handling of .containerignore files described here:

https://github.com/containers/common/blob/main/docs/containerignore.5.md

Note: when the argument to ADD is a git repository, the local .containerignore is not applied.

๐Ÿ—‚๏ธ registries.conf (/etc/containers/registries.conf) ๐Ÿ—‚๏ธ

registries.conf is the configuration file which specifies which container registries should be consulted when completing image names which do not include a registry or domain portion.

๐Ÿ” policy.json (/etc/containers/policy.json) ๐Ÿ”

Signature policy file. This defines the trust policy for container images. Controls which container registries can be used for image, and whether or not the tool should trust the images.


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

buildah(1), cpp(1), buildah-login(1), docker-login(1), namespaces(7), pid_namespaces(7), containers-policy.json(5), containers-registries.conf(5), user_namespaces(7), crun(1), runc(8), containers.conf(5), oci-hooks(5), containers-transports(5), containers-auth.json(5)


๐Ÿ“ FOOTNOTES ๐Ÿ“

  1. The Buildah project is committed to inclusivity, a core value of open source. The master and slave mount propagation terminology used here is problematic and divisive, and should be changed. However, these terms are currently used within the Linux kernel and must be used as-is at this time. When the kernel maintainers rectify this usage, Buildah will follow suit immediately.

and thatโ€™s the whole buildah-build(1) page, bestie โ€” source buildah, date April 2017, manual buildah-build(1). go build something iconic ๐Ÿ’…โœจ๐Ÿซถ

๐Ÿ“ฆ where this page comes from