如何在 docker 中将参数传递给 supervisord?

How to pass an argument to supervisord in docker?

我在 docker 中 运行 宁两个 python 服务。这两种服务都需要一个共同的参数,我在 "docker run"

期间提供了这个参数

目前,我通过从 shell 脚本调用这两个服务来实现这一点。但是,我认为正确的解决方案是在 docker 和 运行 两个服务中使用主管。

我想实现这样的目标:

[program:A]
command=python -m A.py <argument>

[program:B]
command=python -m B.py <argument>

docker文件如下所示:

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 variable LOGLEVEL.

在您的情况下,您的公共参数可以设置在传递给容器的环境变量中,并带有 docker run -d -e "COMMON_ARG=myarg"