Skip to content
Latchkey

docker cp Command Reference

Copy files between a container and the host.

docker cp moves files or directories between a container filesystem and the host in either direction. In CI it extracts artifacts such as compiled binaries, coverage reports, or screenshots from a container so a later step can upload them.

Common flags

  • docker cp CONTAINER:SRC DEST - copy from container to host
  • docker cp SRC CONTAINER:DEST - copy from host to container
  • -a, --archive - preserve uid/gid and permissions
  • -L, --follow-link - follow symlinks in the source

Example

shell
docker cp app-tests:/app/coverage ./coverage
docker cp ./config.json app-web:/etc/app/config.json

In CI

After a containerized test run, docker cp the reports directory out to the workspace, then upload it as an artifact. cp works on stopped containers too, so you can extract output even from a container that has exited.

Key takeaways

  • cp copies in either direction between container and host.
  • It works on stopped containers, so you can extract output post-exit.
  • Common CI use is pulling coverage, reports, or binaries out for artifact upload.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →