简体   繁体   中英

How to access environment variables set by docker run from monit controlled processes inside the container

I'm using monit to start (and monitor) several processes inside of a container. Unfortunately monit runs the processes with a very stripped down environment so anything coming from docker run --env ... is not seen by the process that monit starts. In other environments I would just make sure to source /etc/environment or ~/.bash_profile in the process so get the environment setup.

But docker run --env doesn't have any equivalent AFAIK. Besides having to have a wrapper around monit the creates the monit configuration file or creates /etc/environment is there a way to access these environment variables coming from docker?

just thinking outloud here. just before you run monit, you could collect the environment variables that it has access to. For example:

env | sed 's/^/export /' > /tmp/monit.save.sh

then, later on, when you 'start' in the monit configuration, you could source that file in a bash shell, just like you talked about sourcing /etc/environment. So, just before you start the monit program, source the /tmp/monit.save.sh, then run your program. That will give the monit 'start'ed program access to the environment variables that were passed to the docker container.

however, i may have just described the wrapper you are trying to avoid, sorry if that's the case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM