Docker Engine 29 reference · Containers

docker cp Command (Docker CLI)

Copy files or folders between a container and the host, in either direction, even when the image has no shell.

Docker Engine 29

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH | SRC_PATH CONTAINER:DEST_PATH

Parameters

ParameterDescription
-a Copy with original ownership (archive mode).
-L Follow symbolic links in the source.

Examples

Host to container
docker run -d --name rc-ref-cp alpine:3.24 sleep 300 > /dev/null
echo 'from the host' > note.txt
docker cp note.txt rc-ref-cp:/tmp/note.txt
docker exec rc-ref-cp cat /tmp/note.txt
docker rm -f rc-ref-cp > /dev/null

Output

from the host

Run this on your computer — see “Get Started” for setup.

Container to host (works on stopped containers)
docker run --name rc-ref-cp2 alpine:3.24 sh -c 'echo report-data > /tmp/report.txt'
docker cp rc-ref-cp2:/tmp/report.txt ./report.txt
cat report.txt
docker rm rc-ref-cp2 > /dev/null

Output

report-data

Run this on your computer — see “Get Started” for setup.

Was this page helpful?