Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass environment variable from docker to supervisord

I pass two env variables with docker run:

docker run -d --name foobar -e STAGE=testing -e STAGE_URL=http://...

and the dockerfile kicks of supervisor which launches a couple of processes:

CMD ["/usr/bin/supervisord", "--configuration", "/etc/supervisor/conf.d/supervisord.conf"]

In the supervisord.conf I try to read the variables:

[program:build]
priority=1
autorestart=false
directory=/app/foobar
command=grunt build --force --stage ${STAGE} --stage-url ${STAGE_URL}

I tried also with

$STAGE

and

%(STAGE)s

But STAGE is never treated as a variable. It is never replaced with the actual content. Instead it is treated as a simple string. This results in:

--stage STAGE --stage-url STAGE_URL

instead of

--stage testing --stage-url http://...

Is this even possible what I am doing? Supervisor docs are not clear about this topic. Any ideas?

like image 291
UpCat Avatar asked Apr 07 '16 16:04

UpCat


People also ask

How do I pass an environment variable in Dockerfile?

Use -e or --env value to set environment variables (default []). If you want to use multiple environments from the command line then before every environment variable use the -e flag. Note: Make sure put the container name after the environment variable, not before that.

Should I use Supervisord in Docker?

Also, supervisor is used when we need to run multiple process within the container. I have seen several examples where a container is started from base image and several service are installed and the container is committed to form a new image, all without supervisor.

Is it possible to pass environment variables using Dockerfiles?

Passing Environment Variables Into a DockerfileDockerfile provides a dedicated variable type ENV to create an environment variable. We can access ENV values during the build, as well as once the container runs.

What is Supervisord in Docker?

A supervisor is a tool that allows us to manage a number of different processes simultaneously in Linux like operating system. The supervisor tool requires a . conf file where we specify the processes and different options related to that process like the output log location, auto start, auto restart, etc.


1 Answers

Try %(ENV_STAGE)s.

The docs seem to suggest that's the way to go.

like image 90
Assaf Lavie Avatar answered Sep 28 '22 06:09

Assaf Lavie