Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker copy a file from host to Container?

Tags:

docker

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

like image 378
SHASHI RANJAN Avatar asked Oct 13 '25 11:10

SHASHI RANJAN


1 Answers

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
like image 50
larsks Avatar answered Oct 15 '25 08:10

larsks