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?

Andriy Kopachevskyy
  • 7,276
  • 10
  • 47
  • 56

1 Answers1

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

user2915097
  • 30,758
  • 6
  • 57
  • 59
  • docker cp is just solve all my problems, thanks a lot – Andriy Kopachevskyy Mar 15 '16 at 09:28
  • 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? – Kamil Dziedzic Jul 29 '17 at 13:32
  • 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 http://www.fig.sh/ bundled into docker since docker.com bought them – user2915097 Jul 29 '17 at 14:41
  • 1
    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." https://stackoverflow.com/questions/31578446/running-a-script-inside-a-docker-container-using-shell-script#comment82395122_31578527 – Michael B. May 04 '21 at 00:07