podman-cp(1)
π podman-cp(1) β the General Commands Manual glow-up π
okay so bestie, welcome to podman-cp, straight out of the General Commands Manual section. she's a whole icon, she moves files around, and honestly? she ate. let's get into it π«Ά
β¨ NAME β¨
podman-cp β copy files/folders between a container and the local filesystem. literally that's her whole job and she does it flawlessly π
πΈ SYNOPSIS πΈ
podman cp [options] [container:]src_path [container:]dest_path
podman container cp [options] [container:]src_path [container:]dest_path
two ways in, same energy. pick your fave β¨
π¦ DESCRIPTION π¦
so podman cp copies the contents of src_path to dest_path. you can go container β‘οΈ local machine, local machine β‘οΈ container, or even container β‘οΈ container (yes, she does that, main character behavior fr fr π).
and if you pass - for either SRC_PATH or DEST_PATH, you can stream a tar archive from STDIN or to STDOUT. streaming era, we love to see it π
the containers can be running or stopped, and src_path or dest_path can be a file or a directory. no discrimination here, she's inclusive π
IMPORTANT: thepodman cpcommand assumes container paths are relative to the container's root directory (/), which means supplying the initial forward slash is optional β and therefore she seescompassionate_darwin:/tmp/foo/myfile.txtandcompassionate_darwin:tmp/foo/myfile.txtas identical. same girl, same π
local machine paths can be absolute or relative. the command interprets a local machine's relative paths as relative to the current working directory where podman cp is run. iykyk π
assuming a path separator of /, a first argument of src_path and second argument of dest_path, the behavior is as follows:
src_pathspecifies a file:dest_pathdoes not exist- the file is saved to a file created at
dest_path(note that parent directory must exist).
- the file is saved to a file created at
dest_pathexists and is a file- the destination is overwritten with the source file's contents.
dest_pathexists and is a directory- the file is copied into this directory using the base name from
src_path.
- the file is copied into this directory using the base name from
src_pathspecifies a directory:dest_pathdoes not existdest_pathis created as a directory and the contents of the source directory are copied into this directory.
dest_pathexists and is a file- Error condition: cannot copy a directory to a file. π«
dest_pathexists and is a directorysrc_pathends with/- the source directory is copied into this directory.
src_pathends with/.(i.e., slash followed by dot)- the content of the source directory is copied into this directory.
the command requires src_path and dest_path to exist according to the above rules. no vibes-based exceptions, sorry babe π
if src_path is local and is a symbolic link, the symbolic target is copied by default. she follows the link, she's loyal like that π§
a colon ( : ) is used as a delimiter between a container and its path, and it can also be used when specifying paths to a src_path or dest_path on a local machine β for example, file:name.txt.
IMPORTANT: while using a colon (:) in a local machine path, one must be explicit with a relative or absolute path, for example:/path/to/file:name.txtor./file:name.txtβ
using - as the src_path streams the contents of STDIN as a tar archive. the command extracts the content of the tar to the DEST_PATH in the container. in this case, dest_path must specify a directory. using - as the dest_path streams the contents of the resource (can be a directory) as a tar archive to STDOUT π¦
note that podman cp ignores permission errors when copying from a running rootless container. the TTY devices inside a rootless container are owned by the host's root user and hence cannot be read inside the container's user namespace. not her fault, it's a whole permissions situation π
further note that podman cp does not support globbing (e.g., cp dir/*.txt). to copy multiple files from the host to the container, use xargs(1) or find(1) (or similar tools for chaining commands) in conjunction with podman cp. to copy multiple files from the container to the host, use podman mount CONTAINER and operate on the returned mount point instead (see ALTERNATIVES below). no wildcards bestie, we chain commands in this house π₯
π OPTIONS π
π
--archive, -a
archive mode (copy all UID/GID information). when set to true, files copied to a container have changed ownership to the primary UID/GID of the container. when set to false, maintain UID/GID from archive sources instead of changing them to the primary UID/GID of the destination container. the default is true. so yeah, ownership glow-up by default β¨
π
--overwrite
allow directories to be overwritten with non-directories and vice versa. by default, podman cp errors out when attempting to overwrite, for instance, a regular file with a directory. so if you want that chaos, you gotta opt in π«£
π ALTERNATIVES π
ngl, podman has much stronger capabilities than just podman cp to achieve copying files between the host and containers. she's not the only girl in the group chat π
using standard podman-mount(1) and podman-unmount(1) takes advantage of the entire Linux tool chain, rather than just cp. the whole squad, not just one member π«Ά
copying contents out of a container or into a container can be achieved with a few simple commands. for example:
to copy the /etc/foobar directory out of a container and onto /tmp on the host, the following commands can be executed:
mnt=$(podman mount CONTAINERID)
cp -R ${mnt}/etc/foobar /tmp
podman umount CONTAINERID
to untar a tar ball into a container, following commands can be executed:
mnt=$(podman mount CONTAINERID)
tar xf content.tgz -C ${mnt}
podman umount CONTAINERID
to install a package into a container that does not have dnf installed, following commands can be executed:
mnt=$(podman mount CONTAINERID)
dnf install --installroot=${mnt} httpd
chroot ${mnt} rm -rf /var/log/dnf /var/cache/dnf
podman umount CONTAINERID
by using podman mount and podman unmount, one can use all of the standard Linux tools for moving files into and out of containers, not just the cp command. periodt π
π EXAMPLES π
copy a file from the host to a container:
podman cp /myapp/app.conf containerID:/myapp/app.conf
copy a file from a container to a directory on another container:
podman cp containerID1:/myfile.txt containerID2:/tmp
copy a directory on a container to a directory on the host:
podman cp containerID:/myapp/ /myapp/
copy the contents of a directory on a container to a directory on the host:
podman cp containerID:/home/myuser/. /home/myuser/
copy a directory on a container into a directory on another:
podman cp containerA:/myapp containerB:/newapp
stream a tar archive from STDIN to a container:
podman cp - containerID:/myfiles.tar.gz < myfiles.tar.gz
all of these? iconic. no notes. π
π SEE ALSO π
podman(1), podman-mount(1), podman-unmount(1) β go read these too, they're the supportive besties in this saga π«Ά
and that's the whole page, bestie!! this was podman-cp(1) from the General Commands Manual, and yeah, that's literally the source/version and date situation β no fancy date stamp, just her name and her manual section, and honestly? iconic minimalism π
β¨ go copy some files, you've got this π
π¦ where this page comes from
- alpine 3.24: podman-doc 5.8.9-r0 Β· Apache-2.0
- arch rolling: podman 6.1.4-1 Β· Apache-2.0
- centos-stream 10: podman 7:6.1.0-2.el10 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0
- centos-stream 9: podman 6:5.8.5-2.el9 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0
- fedora 43: podman 5:5.6.2-1.fc43 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0
- fedora 43: podman 5:5.8.4-1.fc43
- fedora 43: podman 5:5.8.8-1.fc43
- fedora 43: podman 5:5.8.9-1.fc43 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0
- fedora 44: podman 5:5.8.1-1.fc44 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0
- fedora 44: podman 5:5.8.7-1.fc44
- fedora 44: podman 5:5.8.9-1.fc44 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0
- nixos 26.05: podman 5.8.9
- nixpkgs unstable: podman 6.1.4
- ubuntu resolute: podman 5.7.0+ds2-3build1 Β· Apache-2.0
- ubuntu stonking: podman 5.8.6+ds1-2 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms