4

How to copy a file from host to a Docker Container? Docker cp is used to copy from container to host but I am not getting any option to copy from host to Container

2 Answers 2

3

First, if you need to make this sort of change, it generally suggests that you need to rethink the architecture of your containers. Options to consider are (a) providing the file at build time via COPY comands in your Dockerfile, or (b) mounting a host directory into your container when you start it, and using that to transfer files in/out.

That said, you could probably arrange to use something like docker exec to get a file into a container:

docker exec -i mycontainer sh -c 'cat > /path/to/destination' < /path/to/source
Sign up to request clarification or add additional context in comments.

1 Comment

thanks .I also find a different way to copy the file to Docker container running on EC2 using sftp
2

Docker cp can be used to copy file from container to host, and host to container as well.

Conteiner to host: sudo docker cp da9230faeb38:/file ./

Host to container: sudo docker cp Desktop/file da9230faeb38:/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.