Skip to content
Latchkey

podman cp: Copy Files To and From Containers

podman cp copies files and directories between a container filesystem and the host, in either direction.

Use podman cp to pull build artifacts or test reports out of a container, or to push a config in. It works whether the container is running or stopped.

What it does

podman cp copies between CONTAINER:PATH and a host path. The direction is set by which side has the container prefix. It handles single files and whole directories and works on stopped containers too.

Common usage

Terminal
# container -> host
podman cp app:/app/coverage ./coverage
# host -> container
podman cp ./config.yml app:/etc/app/config.yml
# copy out a single report file
podman cp tests:/results/junit.xml ./junit.xml

Options

Argument/FlagWhat it does
<container>:<path>Container side of the copy (source or dest)
<host path>Host side of the copy
-a, --archivePreserve ownership and mode where possible
--overwriteAllow overwriting a file with a directory or vice versa

In CI

podman cp is the simplest way to extract JUnit/coverage reports from a test container after the run so the CI step can publish them. It does not need the container running, so copy after the container exits and before podman rm.

Common errors in CI

"Error: no such file or directory" means the in-container path is wrong; check it with podman exec ... ls. "Error: no such container" means the container was already removed; copy before teardown. On rootless Podman, files copied out are owned by your mapped UID, so a later step running as a different user may hit "Permission denied"; use -a or fix ownership.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →