Menu
Coddy logo textTech

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

The 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.txt
challenge icon

Challenge

Medium

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

Verify by reading it back with docker exec:

docker exec mybox cat /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