docker copy file from container to host code example

Example 1: copy files from a docker container to the host machine using cmd

docker cp <containerId>:/file/path/within/container /host/path/target

Example 2: copy file from docker container to host

docker cp <containerId>:/file/path/within/container /host/path/target

Example 3: copy file from host to docker container

docker cp foo.txt mycontainer:/foo.txt

Example 4: docker cp file from host to container

docker cp src/. mycontainer:/target
docker cp mycontainer:/src/. target

Tags:

Misc Example