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 holds a degree in software development and has a strong passion for all things tech-related, especially gadgets with screens. Though he is nostalgic for older phone models, he's a retired gamer and continues to enjoy programming in open-source environments. Additionally, Nikolaus enjoys writing about Linux, macOS and Windows and has experience designing web pages.

Leave a Reply