Copy Into A Container
Part of the Introduction to Docker section of Coddy's Terminal journey — lesson 28 of 40.
Building a file into an image with COPY is permanent. Sometimes you instead want to drop a file into a container that is already running. That is what docker cp does:
docker cp note.txt mybox:/note.txtThe format is docker cp SOURCE CONTAINER:DESTINATION. Here note.txt from your directory is copied to /note.txt inside the container called mybox.
The file really lands in the container, so you can read it back with docker exec:
docker exec mybox cat /note.txtChallenge
MediumA file named data.txt is in your directory. Start a detached nginx container named box, copy data.txt into it at /data.txt, then exec a cat /data.txt to read it back.
Cheat sheet
Copy a file into a running container with docker cp SOURCE CONTAINER:DESTINATION:
docker cp note.txt mybox:/note.txtVerify by reading it back with docker exec:
docker exec mybox cat /note.txtTry it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.