在主管中使用docker环境-e变量 [英] Using docker environment -e variable in supervisor

查看:194
本文介绍了在主管中使用docker环境-e变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been trying to pass in an environment variable to a Docker container via the -e option. The variable is meant to be used in a supervisor script within the container. Unfortunately, the variable does not get resolved (i.e. they stay for instance$INSTANCENAME). I tried ${var} and "${var}", but this didn't help either. Is there anything I can do or is this just not possible?

码头运行命令:

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


推荐答案

p>该变量正在传递给您的容器,但是管理员不会在配置文件中使用这样的环境变量。

The variable is being passed to your container, but supervisor doesn't let use environment variables like this inside the configuration files.

您应该查看主管文档,特别是有关字符串表达式的部分。例如,对于命令选项:

You should review the supervisor documentation, and specifically the parts about string expressions. For example, for the command option:


请注意,命令可能包括Python字符串表达式,例如 / path / to / programname --port = 80%(process_num)02d 可能会扩展到 / path / to / programname --port = / code>在运行时。

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.

字符串表达式是针对包含密钥 group_name host_node_name process_num program_name ,这里(supervisord配置文件的目录)和所有的supervisord的环境变量前缀为 ENV _

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_.

这篇关于在主管中使用docker环境-e变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆