Pass commands from one docker container to another
<p>I have a helper container and an app container. </p>

<p>The helper container handles mounting of code via git to a shared mount with the app container. </p>

<p>I need for the helper container to check for a <code>package.json</code> or <code>requirements.txt</code> in the cloned code and if one exists to run <code>npm install</code> or <code>pip install -r requirements.txt</code>, storing the dependencies in the shared mount.
Thing is the npm command and/or the pip command needs to be run from the app container to keep the helper container as generic and as agnostic as possible.</p>

<p>One solution would be to mount the docker socket to the helper container and run <code>docker exec &lt;command&gt; &lt;app container&gt;</code> but what if I have thousands of such apps on a single host. 
Will there be issues having hundreds of containers all accessing the docker socket at the same time? And is there a better way to do this? Get commands run on another container?</p>

<p>Found that better way I was looking for :-) .</p>

<p>Using supervisord and running the xml rpc server enables me to run something like:</p>

<p><code>supervisorctl -s http://127.0.0.1:9002 -utheuser -pthepassword start uwsgi</code>
<code>supervisorctl -s http://127.0.0.1:9002 -utheuser -pthepassword start uwsgi</code></p>

<p>In the helper container, this will connect to the rpc server running on port 9002 on the app container and execute a program block that may look something like;</p>

<pre><code>[program:uwsgi]
directory=/app
command=/usr/sbin/uwsgi --ini /app/app.ini --uid nginx --gid nginx --plugins http,python --limit-as 512
autostart=false
autorestart=unexpected
stdout_logfile=/var/log/uwsgi/stdout.log
stdout_logfile_maxbytes=0
stderr_logfile=/var/log/uwsgi/stderr.log
stderr_logfile_maxbytes=0
exitcodes=0
environment = HOME="/app", USER="nginx"]
</code></pre>

<p>This is exactly what I needed!</p>

<p>For anyone who finds this you'll probably need your supervisord.conf on your app container to look sth like:</p>

<pre><code>[supervisord]
nodaemon=true

[supervisorctl]

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[inet_http_server]
port=127.0.0.1:9002
username=user
password=password

[program:uwsgi]
directory=/app
command=/usr/sbin/uwsgi --ini /app/app.ini --uid nginx --gid nginx --plugins http,python --limit-as 512
autostart=false
autorestart=unexpected
stdout_logfile=/var/log/uwsgi/stdout.log
stdout_logfile_maxbytes=0
stderr_logfile=/var/log/uwsgi/stderr.log
stderr_logfile_maxbytes=0
exitcodes=0
environment = HOME="/app", USER="nginx"]
</code></pre>

<p>You can setup the inet_http_server to listen on a socket. You can link the containers to be able to access them at a hostname.</p>

python node.js linux git docker