I do have docker container running and I do quite complex script to run inside container. The script is located on host machine. I can't modify Dockerfile How can I place script file to docker vm to run it with docker exec?
1 Answer
you can docker cp your script, and then you run it, with something like docker exec -it container_id script
the doc
https://docs.docker.com/engine/reference/commandline/cp/
You can see some examples at https://hub.docker.com/r/k3ck3c/captvty/
extract
docker exec -it container_id unzip -d ~/Captvty ~/Téléchargements/captvty-2.3.10.zip
answer Yes to All
and
docker exec -it container_id rm ~/Téléchargements/captvty-2.3.10.zip
4 Comments
Andriy Kopachevskyy
docker cp is just solve all my problems, thanks a lot
Kamil Dziedzic
Sadly if you use docker-compose then there is no docker-compose cp cmd:/ Any other way to run
docker exec and provide it shell script from the host?user2915097
if you use docker-compose, you launch containers, so you can still
docker cp you just have to provide the id or the name of the container. Remember docker-compose is just fig fig.sh bundled into docker since docker.com bought themMichael B.
Also checkout
docker exec -i mycontainer bash < mylocal.sh "This reads the local host script and runs it inside the container. You can do this with other things (like .tgz files piped into tar) - its just using the '-i' to pipe into the container process std input." stackoverflow.com/questions/31578446/…