2

If I am on my host machine, I can kickoff a script inside a Docker container using:

docker exec my_container bash myscript.sh

However, let's say I want to run myscript.sh inside my_container from another container bob. If I run the command above while I'm in the shell of bob, it doesn't work (Docker isn't even installed in bob).

What's the best way to do this?

4
  • yes, bind mounting the docker socket is an easy way to do so Commented Feb 20, 2017 at 19:02
  • @user2915097 unfortunately I posted too quickly - when I bind mount and run docker exec ... it gives me cannot connect to the Docker daemon error. Is there something else I need to do in addition to the socket mount? Commented Feb 20, 2017 at 19:03
  • do you launch your container with docker run -it -v /var/run/docker.sock:/var/run/docker.sock and so ? Commented Feb 20, 2017 at 19:08
  • @user2915097 Thank you- Launching the container with both -v /usr/bin/docker:/usr/bin/docker and -v /var/run/docker.sock:/var/run/docker.sock works! If you make your comment into an answer, I will check it. Commented Feb 20, 2017 at 19:12

1 Answer 1

1

Simply launch your container with something like

docker run -it -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker ...

and it should do the trick

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

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.