buildah-copy(1)
π buildah-copy π
okay bestie, welcome to buildah-copy(1) from the General Commands Manual β this is the buildah command that copies files, URLs, and directories into a container's working directory, and it's lowkey iconic β¨
πΈ NAME πΈ
buildah copy copies the contents of a file, a URL, or a directory into a container's working directory. periodt π
π SYNOPSIS π
buildah copy container src [[src ...] dest]
π¦ DESCRIPTION π¦
So basically: it copies the contents of a file, a URL, or a directory to a container's working directory β or to a specified location in the container. If a local directory is specified as a source, its contents are copied to the destination. no cap π«Ά
β¨ OPTIONS β¨
--add-historyβ Add an entry to the history which will note 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, don't return an error if globbing matches nothing. Only meaningful when--allow-wildcardistrue. Defaults tofalse.--allow-wildcardβ Allow glob patterns in source paths. When set tofalse, source paths containing wildcard characters (*,?,[) are rejected with an error. Defaults totrue.--cert-dirpath β Use certificates at path (*.crt,*.cert,*.key) when connecting to registries for pulling images named with the--fromflag. The default certificates directory is/etc/containers/certs.d.--checksumchecksum β Checksum the source content. The value of checksum must be a standard container digest string. Only supported for HTTP sources.--chmodpermissions β Sets the access permissions of the destination content. Accepts numerical or symbolic format. If--fromis not used, defaults to0755.--chownowner:group β Sets the user and group ownership of the destination content. If--fromis not used, defaults to0:0.--contextdirdirectory β Build context directory. Specifying a context directory causes Buildah to chroot into the context directory. This means copying files pointed at by symbolic links outside of the chroot will fail.--excludepattern β Exclude copying files matching the specified pattern. Option can be specified 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 supported formats.--fromcontainerOrImage β Use 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. If--chownor--chmodare not used, permissions and ownership are preserved.--ignorefilefile β Path to an alternative.containerignore(.dockerignore) file. Requires--contextdirbe specified.--linkβ Create an independent image layer for the added files instead of modifying the working container's filesystem. Ifbuildah runcreates a file andbuildah copy --linkadds a file to the same path, the file frombuildah copy --linkwill be present in the committed image. The--linklayer is applied after all container filesystem changes at commit time.--no-follow-symlinksβ Don't follow and dereference the symlinks when copying the files. Instead, copy the symlinks themselves.--parentsβ Preserve leading directories in the paths of items being copied, relative to either the top of the build context, or to the"pivot point", a location in the source path marked by a path component named"."(i.e., where"/./"occurs in the path).--quiet,-qβ Refrain from printing a digest of the copied content.--retryattempts β Number of times to retry in case of failure when performing pull of images from registry. Defaults to3.--retry-delayduration β Duration of delay between retry attempts in case of failure when performing pull of images from registry. Defaults to2s.--timestampseconds β Set 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. The destination directory into which the content is being copied will most likely reflect the time at which the content was added to it.--tls-verifybool-value β Require verification of certificates when pulling images referred to with the--from*flag (defaults totrue). TLS verification cannot be used when talking to an insecure registry.
π EXAMPLE π
run these exactly, bestie:
buildah copy containerID '/myapp/app.conf' '/myapp/app.conf'
buildah copy --exclude=*/.md docs containerID 'docs' '/docs'
buildah copy --parents containerID './x/a.txt' './y/a.txt' '/parents'
buildah copy --chown myuser:mygroup containerID '/myapp/app.conf' '/myapp/app.conf'
buildah copy --chmod 660 containerID '/myapp/app.conf' '/myapp/app.conf'
buildah copy containerID '/home/myuser/myproject.go'
buildah copy containerID '/home/myuser/myfiles.tar' '/tmp'
buildah copy containerID '/tmp/workingdir' '/tmp/workingdir'
buildah copy containerID 'https://github.com/containers/buildah' '/tmp'
buildah copy containerID 'passwd' 'certs.d' /etc
buildah copy containerID '/tmp/myfiles-*' '/dest/'
buildah copy --allow-empty-wildcard=true containerID '/tmp/logs-*' '/dest/'
π FILES π
π« .containerignore/.dockerignore π«
If the .containerignore/.dockerignore file exists in the context directory, buildah copy reads its contents. If both exist, then .containerignore is used.
When the --ignorefile option is specified, Buildah reads it and uses it to decide which content to exclude when copying content into the working container.
Users can specify a series of Unix shell glob patterns in an ignore 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/.dockerignore file:
# here are files we want to exclude
*/*.c
**/output*
src
*/*.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 directorysrcas 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 when copying content into the container.
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)
that's the whole manual, bestie π β source/version is buildah, dated April 2021, and it's the buildah-copy(1) page. mwah π
π¦ 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