Introduction
Copying files with Docker can be confusing. Let’s check out some common docker cp commands for copying files with Docker.
Start with docker ps to obtain your relevant container IDs.
Container to Host
One specific file can be copied to the container like:
docker cp container_id:./bar/foo.txt .
Host to Container
One specific file can be copied from the container like:
docker exec -i container_id sh -c 'cat > ./bar/foo.txt' < ./foo.txtor
docker cp foo.txt mycontainer:/foo.txt
Container to Container
From a container to a container mixes (1) and (2):
docker cp container_id1:./bar/foo.txt .
docker exec -i container_id2 sh -c 'cat > ./bar/foo.txt' < ./foo.txt