Ad space (banner)
AD

Got the fundamentals? A structured Docker course is a fast way to level up.

Find Docker courses on Udemy

Affiliate link. Costs you nothing extra.

🐳Docker Lessons
Lesson 25 / 45

Copying Files with docker cp

When you need to move a file between host and container, use docker cp. It copies in either direction.

The syntax is docker cp source container:destination — or the reverse to copy out of a container.

Running docker cp ./index.html web:/usr/share/nginx/html/ copies your local file into the container's web root.

A common stumble is using it as a deployment method. Files copied this way disappear with the container — for anything permanent, use COPY in the Dockerfile or a volume.

In real work, it is convenient for one-off tasks: pulling out a log file, dropping in a test fixture.

Docker
Try it (type this into the pseudo terminal)
docker cp ./index.html web:/usr/share/nginx/html/

🧑‍💻 You can type this command into the Docker pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)