akshaybetala
akshaybetala

Reputation: 317

How to pass an argument to supervisord in docker?

I am running two python services inside docker. Both services require a common argument, which I provide during "docker run"

Currently, I am achieving this by calling both the services from a shell script. But, I think the proper solution would be using supervisor inside docker and run both the services through it.

I want to achieve something like this:

[program:A]
command=python -m A.py <argument>

[program:B]
command=python -m B.py <argument>

The dockerfile looks like this:

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord"]

How can I pass the argument to supervisor?

Upvotes: 7

Views: 8825

Answers (1)

VonC
VonC

Reputation: 1323953

You could use an environment variable: from supervisor doc

Environment variables that are present in the environment at the time that supervisord is started can be used in the configuration file using the Python string expression syntax %(ENV_X)s:

[program:example]
command=/usr/bin/example --loglevel=%(ENV_LOGLEVEL)s

In the example above, the expression %(ENV_LOGLEVEL)s would be expanded to the value of the environment variable LOGLEVEL.

In your case, your common argument could be set in an environment variable passed to the container with a docker run -d -e "COMMON_ARG=myarg".

Upvotes: 11

Related Questions