buildah-add(1)
π buildah-add β the add-to-container glow-up
Hey bestie, welcome to buildah-add(1) β part of the buildah manual, and honestly? She's kind of a big deal. This is the command that yeets files, URLs, and whole directories straight into your container, no cap. Let's get into it β¨
πΈ SYNOPSIS πΈ
buildah add [options] container src [[src ...] dest]
That's the whole vibe: you got options, you got your container, you got one or more src things, and optionally a dest. Easy. π«Ά
π¦ DESCRIPTION π¦
Okay so what does she actually do? buildah add takes the contents of a file, a URL, or a directory and drops them into a container's working directory β or into whatever specific location in the container you point at. Main character energy, she goes where you tell her. π
Two things to know, and they're lowkey important:
- If a local source file looks like an archive, she doesn't just copy the archive β she extracts its contents and adds those instead. Surprise! π
- If a local directory is your source, its contents get copied to the destination.
No guessing, that's just how it works, fr fr.
β¨ OPTIONS β¨
--add-historyβ Adds a history entry noting the digest of the added content. Defaults tofalse. π
Note: you can also override the default value of--add-historyby setting theBUILDAH_HISTORYenvironment variable:export BUILDAH_HISTORY=true
--allow-empty-wildcardβ If set totrue, she won't throw an error when globbing matches literally nothing. Only meaningful when--allow-wildcardistrue. Defaults tofalse. π--allow-wildcardβ Lets you use glob patterns in source paths. When set tofalse, source paths containing wildcard characters (*,?,[) get rejected with an error. Defaults totrue. π―--cert-dirpath β Uses the certificates at path (*.crt,*.cert,*.key) when connecting to registries to pull images named with the--fromflag, and when connecting to HTTPS servers while fetching sources from locations specified with HTTPS URLs. The default certs directory is/etc/containers/certs.d. π--checksumchecksum β Checksums the source content. The value of checksum has to be a standard container digest string. Only supported for HTTP sources, bestie. π§Ύ--chmodpermissions β Sets the access permissions of the destination content. Takes numerical or symbolic format. π--chownowner:group β Sets the user and group ownership of the destination content. π«Ά--contextdirdirectory β Build context directory. Specifying one makes Buildah chroot into that context directory β which means copying files pointed at by symlinks outside of the chroot will fail. Fair warning. π--excludepattern β Excludes files matching the specified pattern from being copied. You can pass this option multiple times. Patterns are matched against each file's path relative to the context directory (or, with--from, relative to the source container or image root). Seecontainerignore(5)for the supported formats. π--fromcontainerOrImage β Uses the root directory of the specified working container or image as the root directory when resolving absolute source paths and the path of the context directory. If an image needs to be pulled, options recognized bybuildah pullcan be used. π--ignorefilefile β Path to an alternative.containerignore(.dockerignore) file. Requires--contextdirto be specified. π--linkβ Creates an independent image layer for the added files instead of modifying the working container's filesystem. Real talk: ifbuildah runcreates a file andbuildah add --linkadds a file to the same path, the file frombuildah add --linkis the one that shows up in the committed image. The--linklayer gets applied after all container filesystem changes at commit time. π₯--no-follow-symlinksβ When a local source is a symbolic link, copies the link as a symbolic link instead of dereferencing it and copying the contents of the target. πͺ--quiet,-qβ Refrains from printing a digest of the added content. Shhh. π€«--retryattempts β Number of times to retry on failure when pulling images from registries or retrieving content from HTTPS URLs. Defaults to3. π--retry-delayduration β Duration of delay between retry attempts on failure when pulling images from registries or retrieving content from HTTPS URLs. Defaults to2s. β³--timestampseconds β Sets the timestamp ("mtime") for added content to exactly this number of seconds since the epoch (Unix time0, i.e.,00:00:00 UTC on 1 January 1970) to help allow for deterministic builds. β
Heads up though: the destination directory the content is being copied into will most likely reflect the time at which the content was added to it. So don't be shocked. π
--tls-verifybool-value β Requires verification of certificates when retrieving sources from HTTPS locations, or when pulling images referred to with the--from*flag (defaults totrue). Important: TLS verification cannot be used when talking to an insecure registry. π‘οΈ
π§ EXAMPLE π§
Some iconic little demos, go off bestie:
buildah add containerID '/myapp/app.conf' '/myapp/app.conf'
buildah add --chown myuser:mygroup containerID '/myapp/app.conf' '/myapp/app.conf'
buildah add --chmod 660 containerID '/myapp/app.conf' '/myapp/app.conf'
buildah add containerID '/home/myuser/myproject.go'
buildah add containerID '/home/myuser/myfiles.tar' '/tmp'
buildah add containerID '/tmp/workingdir' '/tmp/workingdir'
buildah add containerID 'https://github.com/containers/buildah/blob/main/README.md' '/tmp'
buildah add containerID 'passwd' 'certs.d' /etc
buildah add containerID '/tmp/myfiles-*' '/dest/'
buildah add --allow-empty-wildcard=true containerID '/tmp/logs-*' '/dest/'
π FILES π
.containerignore or .dockerignore
If a .containerignore or .dockerignore file exists in the context directory, buildah add reads its contents. And if both exist? .containerignore wins, obviously. π
When the --ignorefile option is specified, Buildah reads that file and uses it to decide which content to exclude when copying content into the working container.
You can drop a series of Unix shell glob patterns in an ignore file to identify files/directories to exclude. Very cute, very useful. π
Buildah also 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/.dockerignore file:
# here are files we want to exclude
*/*.c
**/output*
src
Breaking that down, because we love clarity:
*/*.cβ Excludes files and directories whose names end with.cin any top level subdirectory. For example, the source fileinclude/rootless.c. π§**/output*β Excludes files and directories starting withoutputfrom any directory. πsrcβ Excludes files namedsrcand the directorysrc, plus any content in it. π
Lines starting with ! (exclamation mark) can be used to make exceptions to exclusions. The following is an example .containerignore file that uses this mechanism:
*.doc
!Help.doc
That one excludes all doc files except Help.doc when copying content into the container. Not me making an exception for the one file that ate. π
This functionality is compatible with the handling of .containerignore files described here:
https://github.com/containers/common/blob/main/docs/containerignore.5.md
π SEE ALSO π
buildah(1), containerignore(5)
And that's the whole page, bestie! π This gem comes to you from the buildah manual, dated April 2021, and you just read buildah-add(1) β go forth and add things to 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