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?
The docker run command:
sudo docker run -d -e "INSTANCENAME=instance-1" -e "FOO=2" -v /var/app/tmp:/var/app/tmp -t myrepos/app:tag
and the supervisor file:
[program:app]
command=python test.py --param1=$FOO
stderr_logfile=/var/app/log/$INSTANCENAME.log
directory=/var/app
autostart=true
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:
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_
.