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?
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.
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.
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.
You could use an environment variable: from supervisor doc
Environment variables that are present in the environment at the time that
supervisordis 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)swould be expanded to the value of the environment variableLOGLEVEL.
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With