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 ishostname:ip. The--add-hostoption can be set multiple times. Conflicts with the--no-hostsoption.
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--platformoption, inspect the build's base images, and build for all of the platforms for which they are all available. Stages that usescratchas 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 theARCHof 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. Seecontainers-auth.json(5)for more information. This file is created usingbuildah 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 formarg=value. The suggested file name isargfile.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 inCOPYinstruction.
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 acceptsdocker://,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:
- Named build context defined with
--build-context [name]=.. - Stage defined with
AS [name]inside Containerfile - 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=1his 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 executingRUNinstructions, 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-addand--cap-drop, it gets dropped, periodt. Order of the options does not matter, so don't try to be slick with it. ๐
--cert-dirpath โ use the certs chillin' at path (*.crt,*.cert,*.key) to connect to the registry, and to pull stuff from HTTPS locations forADDinstructions. The default certs directory is/etc/containers/certs.d. ๐--cgroup-parent=""โ the path to the cgroups where the cgroup forRUNinstructions 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. โจ--cgroupnshow โ sets the config for cgroup namespaces when handlingRUNinstructions. 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 theVOLUMEinstruction (both the ones in this build and the ones inherited from base images) so that their contents can only be modified byADDandCOPYinstructions. Any changesRUNmakes 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-formatformat โ specifies the compression format to use. Supported values are:gzip,zstdandzstd:chunked. Heads up:zstd:chunkedis incompatible with encrypting images, and will be treated aszstdwith a warning in that case. If you don't specify, the format is read from thecompression_formatsetting incontainers.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-levellevel โ specifies the compression level to use. The value is specific to the compression algorithm, e.g. forzstdthe accepted values are in the range1-20(inclusive), while forgzipit's1-9(inclusive). If not specified, the level is read from thecompression_levelsetting incontainers.conf. ๐--cpp-flag=""โ set extra flags to pass to the C Preprocessorcpp(1). Containerfiles ending with a.insuffix get preprocessed viacpp(1), and this option is how you pass additional flags to cpp. Note: you can also set defaultCPPFLAGSby setting theBUILDAH_CPPFLAGSenvironment 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 to100000microseconds.
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-epochor--timestampflag, 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. ๐
--credscreds โ 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. ๐--cwoptions โ produce an image suitable for use as a confidential workload running in a trusted execution environment (TEE) usingkrun(i.e.,crunbuilt with thelibkrunfeature enabled and invoked askrun). Instead of the conventional contents, the root filesystem of the image will contain an encrypted disk image and configuration information forkrun. ๐ต๏ธโโ๏ธ
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,krunis 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, apassphrasevalue 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 thelibkrunfw-sevshared 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 anattestation_urlvalue is specified, a randomly-generated passphrase will be used. The authors recommend setting anattestation_urlbut not apassphrase. ๐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 likeKBorMBare 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-keykey[: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 anyRUNinstructions run during the build. The optional permissions parameter can be used to specify device permissions, using any one or more ofrfor read,wfor write, andmformknod(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. Thecrun(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--dnswith--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-optionwith--network=none. ๐--dns-search=[]โ set custom DNS search domains. Invalid if using--dns-searchwith--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, butenvis set in the current environment, the value from the current environment will be added to the image. The value ofenvcan be overridden byENVinstructions in the Containerfile. To remove an environment variable from the built image, use the--unsetenvoption. ๐ง--file,-f Containerfileโ specifies a Containerfile which contains instructions for building the image, either a local file or anhttporhttpsURL. If more than one Containerfile is specified,FROMinstructions 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 totrueif--compression-formatis explicitly specified on the command-line orcompression_formatis set incontainers.conf,falseotherwise.--force-rm bool-valueโ always remove intermediate containers after a build, even if the build fails (defaultfalse). literally "clean up your mess no matter what" energy ๐ฅ--formatโ control the format for the built image's manifest and configuration data. Recognized formats includeoci(OCI image-spec v1.0, the default) anddocker(version 2, using schema format 2 for the manifest).
๐ก Note: You can also override the default format by setting theBUILDAH_FORMATenvironment variable. Like:export BUILDAH_FORMAT=docker
--fromโ overrides the firstFROMinstruction within the Containerfile. If there are multipleFROMinstructions 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-groupsis 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*.jsonfile in the path configures a hook forbuildah buildcontainers. For more details on the syntax of the JSON files and the semantics of hook injection, seeoci-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 thebuildahprocess. This can be disabled by setting the--http-proxyoption tofalse. The environment variables passed in includehttp_proxy,https_proxy,ftp_proxy,no_proxy, and also the upper case versions of those. ๐ซถ--identity-label bool-valueโ adds a labelio.buildah.versionwith its value set to the version of buildah which built the image (defaulttrueunless--timestampor--source-date-epochis 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--platformis 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--platformis 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. (defaulttrue). Use cases which set this flag tofalsemay need to do the same for the--created-annotationflag. ๐ฆ--inherit-labels bool-valueโ inherit the labels from the base image or base stages. (defaulttrue). ๐ฆ--ipc howโ sets the configuration for IPC namespaces when handlingRUNinstructions. 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 whichbuildahitself 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 ofRUNinstructions. Recognized types includeoci(OCI-compatible runtime, the default),rootless(OCI-compatible runtime invoked using a modified configuration, with--no-new-keyringadded to itscreateinvocation, reusing the host's network and UTS namespaces, and creating private IPC, PID, mount, and user namespaces; the default for unprivileged users), andchroot(an internal wrapper that leans more towardchroot(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 theBUILDAH_ISOLATIONenvironment variable. Like:export BUILDAH_ISOLATION=oci
--jobs Nโ run up toNconcurrent stages in parallel. If the number of jobs is greater than1, stdin will be read from/dev/null. If0is 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. Iflabelis 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--layersistrue. It can be used multiple times. Iflabelis 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 isfalse).
๐ก Note: You can also override the default value of layers by setting theBUILDAH_LAYERSenvironment 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--logfileand--platformis 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. IflistNamedoes not include a registry name component, the registry namelocalhostwill be prepended to the list name. ๐--memory,-m=""โ memory limit (format:[], where unit =b,k,morg)
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 swapLIMITshould always be bigger than the-m(--memory) value. No worries though โ by default the swapLIMITjust gets set to double whatever--memoryis. 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-fileMetadataFile โ writes all the info about the built image into the file you name. ๐ Heads up though: when--platformis specified more than once, trying to use this option will trigger an error. So pick one, diva.--mountmount-instruction โ adds this mount to eachRUNcommand 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 handlingRUNinstructions. ๐
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 mynetto join the network with the namemynet. Only supported for rootful users.pasta[:OPTIONS,...]: usepasta(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 inpasta(1)can be specified as comma-separated arguments. In terms ofpasta(1)options,--config-netis given by default, in order to configure networking when the container is started, and--no-map-gwis also assumed by default, to avoid direct access from container to host using the gateway address. The latter can be overridden by passing--map-gwin the pasta-specific options (despite not being an actualpasta(1)option). Also,-t noneand-u noneare passed to disable automatic port forwarding based on bound ports. Similarly,-T noneand-U noneare 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, assign10.0.2.0/24to thetap0interface in the container, with gateway10.0.2.3, enable DNS forwarder reachable at10.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/hostnamefile in the container forRUNinstructions.
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/hostsfile in the container forRUNinstructions.
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-historybool-value โ omit build history information in the built image (defaultfalse).
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-featurefeature โ set the name of a required operating system feature for the image which will be built. By default, if the image is not based onscratch, 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-versionversion โ set the exact required operating system version for the image which will be built. By default, if the image is not based onscratch, 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).
--pidhow โ sets the configuration for PID namespaces when handlingRUNinstructions. 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 whichbuildahitself 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 examplelinux/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--platformoption may not be used in combination with the--arch,--os, or--variantoptions.
--pullโ pull image policy. If not specified, the default ismissing. If an explicit--pullargument is provided without any value, use thealwaysbehavior. ๐always: pull base and SBOM scanner images from the registries listed inregistries.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 inregistries.confif 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. ๐คซ--retryattempts
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 to2s. 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-epochflag, 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 (defaulttrue). 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 theRUNinstruction. Default isrunc, orcrunwhen machine is configured to use cgroups V2.
Note: You can also override the default runtime by setting theBUILDAH_RUNTIMEenvironment 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 jsontobuildah 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 isfalse). 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-commandvalue 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=ALLor/path/1:/path/2, or shell expanded paths (/proc/*) โ Paths to unmask separated by a colon. If set toALL, 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>.numbermust be greater than0. Unit is optional and can beb(bytes),k(kilobytes),m(megabytes), org(gigabytes). If you omit the unit, the system uses bytes. If you omit the size entirely, the system uses64m.--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 istrue). 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 time0, i.e.,00:00:00 UTC on 1 January 1970) (default is to use the value set in theSOURCE_DATE_EPOCHenvironment 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-filepathname โ gives you the path to a BuildKit-compatible source policy JSON file ๐. once it's set, source references (think base images inFROMinstructions) 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 inupdates.
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 areEXACTandWILDCARD(supports*and?glob patterns). defaults toWILDCARDif you don't specify.
updates: forCONVERTactions, 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 policyCONVERTrules get processed after--build-contextsubstitutions but before any substitutions specified incontainers-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, thenregistries.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 isfalse.) ๐ซถ
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 ofdefault=$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 eithermode,uidorgidoptions along with the mount options. like, here's how you make the ssh socket available to an app user withuid=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-labelsbool-value โ slaps metadata labels onto all the intermediate stage images of your multistage build, final image included (default isfalse). but bestie, this one requires--save-stagesto 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 (fromFROM ... AS alias), or the stage position if no alias is specifiedio.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 theRUNcontainers. sometimes commands beingRUNinside a Containerfile wanna ask the user stuff. thinkaptasking you to confirm an install ๐. use--stdinso you can actually interact from the terminal during the build.--tag,-timageName โ sets the name assigned to the resulting image if the build completes successfully ๐. if imageName doesn't include a registry name component, the registry namelocalhostgets 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 .
--targetstageName โ sets the target build stage to build ๐ฏ. when you're building a Containerfile with multiple build stages,--targetlets you name an intermediate build stage as the final stage for the resulting image. anything after the target stage gets skipped, periodt.--timestampseconds โ 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-verifybool-value โ requires HTTPS and certificate verification when talking to container registries (defaults totrue) and when retrieving content from HTTPS locations forADDinstructions ๐. and nope, TLS verification cannot be used when talking to an insecure registry. safety first but also rules are rules.--ulimittype=soft-limit[:hard-limit] โ specifies resource limits to apply to processes launched when processingRUNinstructions. 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)
--unsetannotationannotation โ unsets the image annotation, so it does not get inherited from the base image ๐ซ. bye felicia.--unsetenvenv โ unsets environment variables from the final image ๐ธ--unsetlabellabel โ unsets the image label, so it does not get inherited from the base image. same energy, different field ๐--usernshow โ sets the config for user namespaces when handlingRUNinstructions. 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. ifsizeis not specified,autowill 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-mapmapping โ directly specifies a GID mapping to be used to set ownership, at the filesystem level, on the working container's contents ๐๏ธ. commands run when handlingRUNinstructions 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-groupgroup
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
zoption 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
Zoption 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
Oflag is not allowed to be specified with theZorzflags. 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_PROXYHTTPS_PROXYFTP_PROXYNO_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 usinggit://for performing clone operation due to recent changes in their security guidance (https://github.blog/2021-09-01-improving-git-protocol-security-github/). Use anhttps://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 arexz,bzip2,gzipandidentity(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 keysinsecureRegistries,blockedRegistries, andallowedRegistries.
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โ TheTMPDIRenvironment 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 toADDis a git repository, the local.containerignoreis 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 ๐
- 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
- centos-stream 10: buildah 2:1.45.0-2.el10 ยท Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms