将命令从一个docker集装箱传递到另一个

我有一个帮手容器和一个应用程序容器。

帮助程序容器通过git处理代码通过应用程序容器共享安装。

我需要帮助程序容器检查克隆代码中的package.jsonrequirements.txt ,如果存在要运行npm installpip install -r requirements.txt ,则将依赖项存储在共享安装中。 事情是npm命令和/或pip命令需要从应用程序容器运行,以保持辅助容器为通用和尽可能不可知的。

一个解决scheme是将docker套接字挂载到helper容器并运行docker exec <command> <app container>但是如果在单个主机上有成千上万个这样的应用程序呢。 会有数百个容器同时访问docker套接字吗? 还有更好的方法来做到这一点? 获取命令在另一个容器上运行?

那么没有像“ssh”那样的“容器到容器”的内部通信层。 在这方面,容器与2个不同的虚拟机(一般networking部分旁边)是独立的。

您可以按照通常的方式,在“接收”服务器上安装opensshd-server,仅将其configuration为基于键。 您不需要将端口导出到主机,只需使用docker内部networking连接到端口即可。 在容器启动时间(卷装载)期间,将“调用者服务器”上的ssh私钥和公共密钥部署到“接收服务器”上的.ssh / authorized_keys中,以便不保留图像中的秘密(构build时间)。

也许还会在.ssh / config中创build一个ssh-alias,并将HostVerify设置为no,因为容器可能会重build。 然后做

 ssh <alias> your-command 

find更好的方式,我正在寻找:-)。

使用supervisord并运行xml rpc服务器使我能够运行如下所示:

supervisorctl -s http://127.0.0.1:9002 -utheuser -pthepassword start uwsgi supervisorctl -s http://127.0.0.1:9002 -utheuser -pthepassword start uwsgi

在辅助容器中,这将连接到应用程序容器上的端口9002上运行的rpc服务器,并执行一个可能看起来像这样的程序块;

 [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"] 

这正是我所需要的!

对于任何发现这一点的人来说,你可能需要你的app容器上的supervisord.conf来看起来像:

 [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"] 

您可以设置inet_http_server以在套接字上侦听。 您可以链接容器以便能够以主机名访问它们。