SELECTIVE

How to copy file from host system to docker container?

The quickest way to transfer/copy files from the host system to docker containers is using the “docker cp” command.

The command will be as follows

# Replace the local file path which you want to copy
# Change the file path on source and destination
docker cp /path/to/local/file.txt mycontainer_id:/path/to/container/file.txt

By running “docker ps -a” you can see the ID of the container

Use the “docker exec -it” command to check if the location exists inside the container.

docker exec -it f39ff450f84b sh 

If everything is okay, run the docker cp command with parameters, and your file will be copied to the docker container.

docker cp /path/to/local/file.txt mycontainer_id:/path/to/container/file.txt

Did this post help you?

Tutsplanet brings in-depth and easy tutorials to understand even for beginners. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:

  • Just want to thank us? Buy us a Coffee
  • May be another day? Shop on Amazon using our links.
    Your prices won’t change but we get a small commission.


Editorial Staff

Editorial Staff at Tutsplanet is a dedicated team to write various tutorials about subjects like Programming, Technology and Operating Systems.

Related Articles

Back to top button