Copy Out Of A Container
Part of the Introduction to Docker section of Coddy's Terminal journey — lesson 29 of 40.
docker cp works in both directions. Swapping the order of the arguments copies a file out of a container and back onto your machine:
docker cp mybox:/note.txt ./back.txtNow the container's /note.txt is saved as back.txt in your current directory, where you can read it with plain cat:
cat back.txtThis is how you pull results out of a container: logs, generated files, or anything a container produced while it ran.
Challenge
MediumStart a detached nginx container named src. Use docker exec with sh -c to write output ready into result.txt inside it. Then copy result.txt out to ./result.txt and cat it.
Cheat sheet
Copy a file out of a container using docker cp (container path first, host path second):
docker cp mybox:/note.txt ./back.txtCopy a file into a container (host path first, container path second):
docker cp ./back.txt mybox:/note.txtTry it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.