7

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 1

5

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

Sign up to request clarification or add additional context in comments.

4 Comments

docker cp is just solve all my problems, thanks a lot
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?
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 them
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/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.