# Execute Script on one Container from Another

**URL:** <https://forums.docker.com/t/execute-script-on-one-container-from-another/49241>\
**Category:** General\
**Tags:** docker\
**Created:** [April 11, 2018, 4:11am UTC](https://forums.docker.com/t/execute-script-on-one-container-from-another/49241 "2018-04-11T04:11:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattbenett](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mattbenett](https://forums.docker.com/u/mattbenett)\
**Post date:** [April 11, 2018, 4:11am UTC](https://forums.docker.com/t/execute-script-on-one-container-from-another/49241/1 "2018-04-11T04:11:06Z")

</div>

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?

thanks

---

<div class="post-metadata">

**Author:** ![blacklabelops](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/blacklabelops/32/19596_2.png) [@blacklabelops](https://forums.docker.com/u/blacklabelops)\
**Post date:** [April 18, 2018, 8:30pm UTC](https://forums.docker.com/t/execute-script-on-one-container-from-another/49241/2 "2018-04-18T20:30:33Z")

</div>

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/](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](https://github.com/msoap/shell2http)
