Skip to content
Latchkey

docker cp: Copy Files To & From Containers

Copy files between the host and a container - great for pulling CI artifacts out.

docker cp copies files and directories between a container filesystem and the host. This page covers both directions and the path semantics that trip people up.

What it does

docker cp moves files between CONTAINER:PATH and a host path, in either direction. It works on running and stopped containers, which makes it a clean way to extract build artifacts in CI.

Common usage

Terminal
docker cp web:/app/dist ./dist          # container -> host
docker cp ./config.yml web:/etc/app/    # host -> container
docker cp web:/var/log/app.log ./logs/

Common errors in CI

"no such file or directory" usually means the source path inside the container is wrong - verify with docker exec ls. A trailing-slash subtlety: copying a directory src to dst/ places src inside dst, while dst (no slash) can rename it; be explicit. To extract artifacts from a build container in CI, create the container, docker cp the output, then docker rm it.

Related guides

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