我正在 docker 中运行两个 python 服务。这两种服务都需要一个共同的参数,我在“docker run”期间提供了该参数
目前,我通过从 shell 脚本调用这两个服务来实现这一目标。但是,我认为正确的解决方案是在 docker 内部使用主管并通过它运行这两个服务。
我想要实现这样的目标:
[program:A]
command=python -m A.py <argument>
[program:B]
command=python -m B.py <argument>
dockerfile 如下所示:
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord"]
如何将论点传递给主管?
最佳答案
您可以使用环境变量:来自 supervisor doc
Environment variables that are present in the environment at the time that
supervisord
is started can be used in the configuration file using the Python string expression syntax%(ENV_X)s
:
[program:example]
command=/usr/bin/example --loglevel=%(ENV_LOGLEVEL)s
In the example above, the expression
%(ENV_LOGLEVEL)s
would be expanded to the value of the environment variableLOGLEVEL
.
在您的情况下,您的公共(public)参数可以设置在使用 docker run -d -e "COMMON_ARG=myarg"传递给容器的环境变量中。
关于docker - 如何在docker中将参数传递给supervisord?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38844666/