buildah-commit(1)
okay bestie, welcome to buildah-commit(1) from the General Commands Manual β the page that teaches you how to create an image from a working container, and it is lowkey iconic β¨
β¨ NAME β¨
buildah-commit β create an image from a working container. Thatβs it, thatβs the whole assignment π
π οΈ SYNOPSIS π οΈ
buildah commit [options] container [image]
π DESCRIPTION π
okay so hereβs the tea: this command writes a new image using the specified containerβs read-write layer, and if that container is based on an image, it also uses the layers of that image π«Ά
About the image name: if it does not begin with a registry name component, localhost gets added to the name. If image is not provided at all, the image will have no name. And when an image has no name, the buildah images command will display <none> in the REPOSITORY and TAG columns β no cap π
The image value supports all transports from containers-transports(5). If no transport is specified, the containers-storage (i.e., local storage) transport is used. Slay.
π RETURN VALUE π
The image ID of the image that was created. On error, 1 is returned and errno is returned. periodt.
π OPTIONS π
--add-file source[:destination]β read the contents of filesourceand add it to the committed image as a file atdestinationπ. Ifdestinationis not specified, the path ofsourcewill be used. The new file will be owned by UID0, GID0, have0644permissions, and be given the timestamp specified to the--timestampoption if it is specified. This option can be specified multiple times.--annotation annotation[=value]β add an image annotation (e.g.annotation=value) to the image metadata. Can be used multiple times. Ifannotationis 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.--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.jsonis checked, which is set usingdocker login. Note: you can also override the default path of the authentication file by setting theREGISTRY_AUTH_FILEenvironment variable:export REGISTRY_AUTH_FILE=path.--cert-dir pathβ use certificates atpath(*.crt,*.cert,*.key) to connect to the registry. The default certificates directory is/etc/containers/certs.d.--change, -c "INSTRUCTION"β apply the change to the committed image that would have been made if it had been built using a Containerfile which included the specified instruction. This option can be specified multiple times.--compression-format formatβ specifies the compression format to use. Supported values are:gzip,zstdandzstd:chunked. If not specified, the format is read from thecompression_formatsetting incontainers.conf. Cannot be used together with--disable-compression.--compression-level levelβ specifies the compression level to use. The value is specific to the compression algorithm used, e.g. forzstdthe accepted values are in the range1-20(inclusive), while forgzipit is1-9(inclusive). If not specified, the level is read from thecompression_levelsetting incontainers.conf.--config filenameβ read a JSON-encoded version of an image configuration object from the specified file, and merge the values from it with the configuration of the image being committed.--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 is 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 the value can be entered. The password is entered without echo.--cw optionsβ 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 which will be 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 separated by+. If not specified, buildah guesses that25%more space than the contents will be enough, but this option is provided in case its guess is wrong. If the specified or computed size is less than10megabytes, it will be increased to10megabytes.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.
--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. Cannot be used together with--compression-formator--force-compression.--encrypt-layer layer(s)β layer(s) to encrypt: 0-indexed layer indices with support for negative indexing (e.g.0is the first layer,-1is the last layer). If not defined, will encrypt all layers if theencryption-keyflag is specified.--encryption-key keyβ the[protocol:keyfile]specifies the encryption protocol, which can beJWE(RFC7516),PGP(RFC4880), andPKCS7(RFC2315) and the key material required for image encryption. For instance,jwe:/path/to/key.pemorpgp:admin@example.comorpkcs7:/path/to/x509-file.--force-compressionβ if set, commit 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.--format, -f [oci | docker]β control the format for the image 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:export BUILDAH_FORMAT=docker.--identity-label bool-valueβ adds a labelio.buildah.versionwith its value set to the version of buildah which committed the image (defaulttrueunless--timestampor--source-date-epochis used).--iidfile ImageIDfileβ write the image ID to the file.--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.--metadata-file MetadataFileβ write information about the committed image to the named file.--omit-history bool-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-historyto 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.--pullβ when the--pullflag is enabled or set explicitly totrue(with--pull=true), attempt to pull the latest versions of SBOM scanner images from the registries listed inregistries.confif a local SBOM scanner image does not exist or the image in the registry is newer than the one in local storage. Raise an error if the SBOM scanner image is not in any listed registry and is not present locally.- If the flag is disabled (with
--pull=false), do not pull SBOM scanner images from registries, use only local versions. Raise an error if a SBOM scanner image is not present locally. - If the pull flag is set to
always(with--pull=always), pull SBOM scanner images from the registries listed inregistries.conf. Raise an error if a SBOM scanner image is not found in the registries, even if an image with the same name is present locally. - If the pull flag is set to
missing(with--pull=missing), pull 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.
- If the flag is disabled (with
Okay so if the pull flag is set to never (with --pull=never), do not pull SBOM scanner images from registries β use only the local versions. If the image isn't present locally, it raises an error. Like, no cap, it's not gonna go fetch it for you. π
ββοΈ
--quiet,-qβ when writing the output image, suppress the progress output. Silence is golden, bestie.--rewrite-timestampβ when generating the new layer for the image, make sure 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 that are later than that value with that value. Time crime = corrected. β°--rmβ remove the working container and its contents after creating the image. The default leaves the container and its content in place. (So if you don't pass this, your container is still chilling there afterwards π)--sbompreset β 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-outputpath β when generating SBOMs, store the generated SBOM in the specified path in the output image. There is no default. β¨--sbom-image-purl-outputpath β when generating SBOMs, scan them for PURL (package URL) information, and save a list of found PURLs to the named file in the local filesystem. There is no default. (The package URL spec lives athttps://github.com/package-url/purl-spec/blob/master/PURL-SPECIFICATION.rst, iykyk π«Ά)--sbom-merge-strategymethod β 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-outputfile β when generating SBOMs, store the generated SBOM in the named file on the local filesystem. There is no default. πΈ--sbom-purl-outputfile β when generating SBOMs, scan them for PURL (package URL) information, and save a list of found PURLs to the named file in the local filesystem. There is no default. (Same spec link as above:https://github.com/package-url/purl-spec/blob/master/PURL-SPECIFICATION.rstβ go read it, it's giving documentation π )--sbom-scanner-commandimage β 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-imageimage β generate SBOMs using the specified scanner image. π§--sign-byfingerprint β sign the new image using the GPG key that matches the specified fingerprint. Signature slay. βοΈ--source-date-epochseconds β set the"created"timestamp for the image to this number of seconds since the epoch (Unix time 0, i.e.,00:00:00 UTC on 1 January 1970) to make it easier to create deterministic builds (defaults to$SOURCE_DATE_EPOCHif set, otherwise the current time will be used).
The "created" timestamp is written into the image's configuration and manifest when the image is committed, so committing the same working container at two different times will produce images with different sha256 hashes, even if no other changes were made to the working container in between. π (yes, really, the hash changes just from time passing)
When --source-date-epoch is set, the "created" timestamp is always set to the time specified, which should allow for identical images to be committed at different times.
Conflicts with the similar --timestamp flag, which also sets its specified time on layer contents. β οΈ
--squashβ squash all of the new image's layers (including those inherited from a base image) into a single new layer. Flatten it, periodt. π«--timestampseconds β set the"created"timestamp for the image to this number of seconds since the epoch (Unix time 0, i.e.,00:00:00 UTC on 1 January 1970) to make it easier to create deterministic builds (defaults to current time).
The "created" timestamp is written into the image's configuration and manifest when the image is committed, so committing the same working container at two different times will produce images with different sha256 hashes, even if no other changes were made to the working container in between.
When --timestamp is set, the "created" timestamp is always set to the time specified, which should allow for identical images to be committed at different times. All content in the new layer added as part of the image will also bear this timestamp.
Conflicts with the similar --source-date-epoch flag, which by default does not affect the timestamps of layer contents. β οΈ
--tls-verifybool-value β require HTTPS and verification of certificates when talking to container registries (defaults totrue). TLS verification cannot be used when talking to an insecure registry. π--unsetannotationannotation β unset the image annotation, causing the annotation not to be inherited from the base image. Bye bye annotation π--unsetenvenv β unset environment variables from the final image.
π EXAMPLE π
This example saves an image based on the container:
buildah commit containerID newImageName
This example saves an image named newImageName based on the container and removes the working container:
buildah commit --rm containerID newImageName
This example commits to an OCI archive file named /tmp/newImageName based on the container:
buildah commit containerID oci-archive:/tmp/newImageName
This example saves an image with no name, removes the working container, and creates a new container using the image's ID:
buildah from $(buildah commit --rm containerID)
This example saves an image based on the container disabling compression:
buildah commit --disable-compression containerID
This example saves an image named newImageName based on the container disabling compression:
buildah commit --disable-compression containerID newImageName
This example commits the container to the image on the local registry while turning off tls verification:
buildah commit --tls-verify=false containerID docker://localhost:5000/imageId
This example commits the container to the image on the local registry using credentials and certificates for authentication:
buildah commit --cert-dir ~/auth --tls-verify=true --creds=username:password containerID docker://localhost:5000/imageId
This example commits the container to the image on the local registry using credentials from the /tmp/auths/myauths.json file and certificates for authentication:
buildah commit --authfile /tmp/auths/myauths.json --cert-dir ~/auth --tls-verify=true --creds=username:password containerID docker://localhost:5000/imageName
This example saves an image based on the container, but stores dates based on epoch time:
buildah commit --timestamp=0 containerID newImageName
Building an multi-architecture image using the --manifest option (requires emulation software)
#!/bin/sh
build() {
ctr=$(./bin/buildah from --arch $1 ubi8)
./bin/buildah run $ctr dnf install -y iputils
./bin/buildah commit --manifest ubi8ping $ctr
}
build arm
build amd64
build s390x
π ENVIRONMENT π
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 committing an image, if the image is to be given a name, the portion of the name that corresponds to a registry is compared to the items in the blockedRegistries list, and if it matches any of them, the commit attempt is denied. If there are registries in the allowedRegistries list, and the portion of the name that corresponds to the registry is not in the list, the commit attempt is denied. Like, denied 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 π
Okay bestie, these are the config files doing the behind-the-scenes work. Lowkey obsessed with how much power they hold π
/etc/containers/registries.conf(that'sregistries.conf) β this is the config file that says which container registries should be consulted when it's completing image names that don't already include a registry or domain portion. Like, if you're being vague about where an image lives, this file is the one that fills in the blanks π¦/etc/containers/policy.json(yup,policy.json) β the signature policy file, and she's kind of a big deal π This defines the trust policy for container images. It controls which container registries can be used for an image, and whether or not the tool should trust the images. So basically it's the vibe check for trust β¨
π SEE ALSO π
Go read these next, fr fr β your girl does not gatekeep π
buildah(1)buildah-images(1)containers-policy.json(5)containers-registries.conf(5)containers-transports(5)containers-auth.json(5)
and that's the whole page, bestie!! π«Ά You just read the buildah manual for buildah-commit(1) β dated March 2017, from the buildah source π Go forth and commit your containers, you absolute icon βπ
π¦ 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