在主管中使用 docker 环境 -e 变量

Using docker environment -e variable in supervisor

我一直在尝试通过 -e 选项将环境变量传递给 Docker 容器。该变量旨在用于容器内的主管脚本。不幸的是,该变量没有得到解析(即它们保持不变 $INSTANCENAME)。我尝试了 ${var}"${var}",但这也没有帮助。有什么我可以做的吗?或者这是不可能的?

docker运行命令:

sudo docker run -d -e "INSTANCENAME=instance-1" -e "FOO=2" -v /var/app/tmp:/var/app/tmp -t myrepos/app:tag

和主管文件:

[program:app]
command=python test.py --param1=$FOO
stderr_logfile=/var/app/log/$INSTANCENAME.log
directory=/var/app
autostart=true

正在将变量传递给您的容器,但主管不允许在配置文件中使用这样的环境变量。

您应该复习 supervisor documentation,尤其是关于字符串表达式的部分。例如,对于 command 选项:

Note that the value of command may include Python string expressions, e.g. /path/to/programname --port=80%(process_num)02d might expand to /path/to/programname --port=8000 at runtime.

String expressions are evaluated against a dictionary containing the keys group_name, host_node_name, process_num, program_name, here (the directory of the supervisord config file), and all supervisord’s environment variables prefixed with ENV_.