Multi-container running a script in another container


I have one container hosting a web application and 2nd container communicating with an external board (wiringPi). Is there a way I can run scripts on the 2nd container from some php in the first container? I want to query voltage and change some settings on the external board from the web interface.

I can’t work out how I might go about achieving communication between the two. On stack overflow (r.e. docker) there is some discussion about installing openSSH onto the 2nd container and ssh’ing into this from the first container, is that a sensible route and do you have any examples of this approach? Alternatively I could combine all elements into one container but it will be a lot of installation steps and a big image for the one container.

Thanks for your help,

Hey there @tennisparty

My first question would be if you do actually need two separate containers for this. A good principle to bear in mind when architecting your app is that there should be a separate container for every concurrently running process.

It sounds like there are some scripts that you run when required that change the settings and query voltage, in which case they’re not needed to run continuously. In my opinion, if I’ve understood your use case correctly, I would install the scripts and libraries needed to access your external board alongside the web interface, and have the web app call these in the background as necessary.

Alternatively, if you did want to keep things separate, consider making them available on the network (e.g. via HTTP). The first container would make an HTTP request to a server listening on the second which would then run the scripts, but this seems a little unnecessary if you could do everything in one container. The SSH approach could definitely be made to work but feels a little hacky to me.

If you’re working on it feel free to share your project and we can take a look in more detail :+1:

Thanks Chris,

That’s a super useful rule to use. I’ll take a look and see if it’s best to combine.

Really appreciate your help,