Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 523
akshaybetala Avatar asked Aug 09 '16 07:08

akshaybetala


People also ask

What is Supervisord in Docker?

Your Ubuntu 18.04 docker image will require a one-time configuration of Supervisord to get started with process monitoring. Supervisord — A Process Control System, which will run and manage your command-based programs from a simple configuration file setup.

Should I use Supervisord in Docker?

Yes, although it depends on how your main process runs (foreground or background), and how it collects child processes. docker stop stops a running container by sending it SIGTERM signal, let the main process process it, and after a grace period uses SIGKILL to terminate the application.

What user does Supervisord run as?

To be able to run any subprocess as a different user from what supervisord is running as, you must run supervisord as root. It tells you if you run multiple subprocesses, you have to run as a root to be able to start all the subprocesses, meaning that if you have more than 2 projects in you supervisord.


1 Answers

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".

like image 65
VonC Avatar answered Nov 16 '22 03:11

VonC