从主管子进程运行的docker中传递的访问环境变量

时间:2016-07-24 02:37:47

标签: docker supervisord

我正在使用以下命令运行docker容器:

docker run -it -e CustomEnvVariable="val123" -p 80:80 imagename

该图片已运行supervisor以及我的应用的以下配置文件:

[program:myapp]
command=/usr/bin/dotnet /root/myapp/myapp.dll
directory=/root/myapp/
autostart=true
autorestart=true
stderr_logfile=/var/log/myapp.err.log
stdout_logfile=/var/log/myapp.out.log
environment=ASPNETCORE__ENVIRONMENT=Production
stopsignal=INT
user=root

主管启动后,如何从myapp中访问CustomEnvVariable

我在conf文件environment值中尝试了以下值:

environment=ASPNETCORE__ENVIRONMENT=Production,CustomEnvVariable=%(ENV_CustomEnvVariable)s

但重启主管时会收到此错误:

Restarting supervisor: Error: 
Format string 'ASPNETCORE__ENVIRONMENT=Production,CustomEnvVariable="%(ENV_CustomEnvVariable)s"' 
for 'environment' contains names which cannot be expanded

更多信息:

使用主管版本:3.0(通过apt-get install supervisor -y安装)。

我通过检查CustomEnvVariable的输出确认echo $CustomEnvVariable的值已到达容器。

我快速扫描了应用程序可用的所有环境变量,结果如下:

{
  "LC_ADDRESS": "",
  "SUPERVISOR_PROCESS_NAME": "myapp",
  "LC_MONETARY": "",
  "LC_MESSAGES": "",
  "LC_NAME": "",
  "SUPERVISOR_ENABLED": "1",
  "SUPERVISOR_SERVER_URL": "unix:///var/run/supervisor.sock",
  "LC_COLLATE": "",
  "ASPNETCORE__ENVIRONMENT": "Production",
  "SUPERVISOR_GROUP_NAME": "myapp",
  "LANG": "",
  "LC_NUMERIC": "",
  "LANGUAGE": "",
  "LC_PAPER": "",
  "LC_IDENTIFICATION": "",
  "LC_CTYPE": "",
  "LC_MEASUREMENT": "",
  "TERM": "xterm",
  "LC_TIME": "",
  "LC_ALL": "",
  "PATH": "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin",
  "LC_TELEPHONE": "",
  "PWD": "/"
}

1 个答案:

答案 0 :(得分:1)

语法正确,但环境扩展仅在版本>中可用。 3.2主管,as per this github issue