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 hostdocker 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.jsonIn 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
docker run Command ReferenceReference for docker run in CI: --rm, -e, -v, --network, -w, and --entrypoint flags for creating and starting…
docker exec Command ReferenceReference for docker exec in CI: run a command inside a running container with -e, -w, -u, and -i to drive mi…
docker logs Command ReferenceReference for docker logs in CI: fetch container stdout and stderr with --tail, --since, --timestamps, and -f…