How to copy files from host to Docker container

To copy files from your current to a Docker container, follow the steps below. One given file can be copied using the cp command to the Docker container. This can be achieved using the command below:

docker cp file.txt dockercontainer:/file.txt                   [copy files to docker container]

To copy the file FROM the container , use the command:

docker cp dockercontainer:/file.txt file.txt

Read: How to remove old Docker containers

Note that dockercontainer is a container ID (and not an image ID).

To copy several files within a folder fld to the target folder, run the commands:

docker cp fld/. dockercontainer:/target.    [docker cp example]

docker cp dockercontainer:/fld/. target

You may want to check the documentation here.

Read: How to clean up unused Docker containers, images and volumes

Answer due to this user.


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.


Nikolaus Oosterhof

Nikolaus has a degree in software development. He is passionate about gadgets with a screen, nostalgic for phones, a retired gamer and open source programmer. He likes also to write about macOS and Windows. design web pages and debug long programs!

Leave a Reply