Execute Script on one Container from Another

I am sure this is easy, but I am lost.

I have a container running PHP/Apache, that is running a site that asks a few questions, then needs to execute a script.sh on a different linked container with parameters from my web site.

I could put the script and the PHP on the same container, but like to idea of separation (the script has a lot of dependencies that I would prefer not to load up on the PHP container), and I was sure that is what linking was supposed to help with. My question is:

From the PHP container, how do I run a script with parameters on a different linked container?


I would use the docker client’s command: docker exec

In order to docker exec from one container into another you need to install the docker client inside the client container and the client container needs to mount the docker socket:

docker run -v /var/run/docker.sock:/var/run/docker.sock

Code examples for dockerfiles docker clients can be found here: https://hub.docker.com/_/docker/

Then start the target container with a static service name:

docker run --name

Afterwards you can execute from your source container’s command line the target container’s script:

docker exec targetcontainer /bin/bash -c "command arguments"

If you do not want to expose your docker.sock then you can also expose your script through http: https://github.com/msoap/shell2http