Menu
Coddy logo textTech

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.txt

Now the container's /note.txt is saved as back.txt in your current directory, where you can read it with plain cat:

cat back.txt

This is how you pull results out of a container: logs, generated files, or anything a container produced while it ran.

challenge icon

Challenge

Medium

Start 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.txt

Copy a file into a container (host path first, container path second):

docker cp ./back.txt mybox:/note.txt

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Introduction to Docker