Supervisor / supervisor

Supervisor process control system for Unix (supervisord)
http://supervisord.org
Other
8.53k stars 1.25k forks source link

Error when starting supervisor with environment variables in Docker #1608

Open ronyantonydev opened 1 year ago

ronyantonydev commented 1 year ago

Description

When attempting to start the supervisor service in a Docker container, an error related to environment variable expansion in supervisor.conf is encountered. The environment variables for database connection details (DB_HOST, DB_DATABASE, DB_USERNAME, DB_PASSWORD) do not seem to be recognized.

Steps to Reproduce

  1. Build a Docker image using the provided Dockerfile.
  2. Run the Docker container.
  3. Attempt to start the supervisor service.
  4. The error is observed.

Expected Behavior

The supervisor service should start without any issues, correctly utilizing the environment variables set in the Dockerfile.

Actual Behavior

Starting supervisor results in an error due to the inability to expand the format strings for the database connection environment variables.

Error Message

Starting supervisor: Error: Format string 'DB_HOST=%(ENV_DB_HOST)s,DB_DATABASE=%(ENV_DB_DATABASE)s,DB_USERNAME=%(ENV_DB_USERNAME)s,DB_PASSWORD=%(ENV_DB)s which cannot be expanded. Available names: ENV_LANG, ENV_LANGUAGE, ENV_LC_ADDRESS, ENV_LC_ALL, ENV_LC_COLLATE, ENV_LC_CTYPE, ENV_LC_IDENTIFICATION, ENV_LC_MEASUERIC, ENV_LC_PAPER, ENV_LC_TELEPHONE, ENV_LC_TIME, ENV_PATH, ENV_PWD, ENV_TERM, group_name, here, host_node_name, numprocs, process_num, program_name in sectil-worker.conf')

## `Dockerfile` Snippet

ARG DB_HOST
ARG DB_DATABASE
ARG DB_USERNAME
ARG DB_PASSWORD

ENV DB_HOST=${DB_HOST}
ENV DB_DATABASE=${DB_DATABASE}
ENV DB_USERNAME=${DB_USERNAME}
ENV DB_PASSWORD=${DB_PASSWORD}

COPY ./docker/supervisor.conf /etc/supervisor/conf.d/laravel-worker.conf

## `supervisor.conf` Snippet

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/bin/php /var/www/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=www-data
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/storage/logs/worker.log
stopwaitsecs=3600
environment=DB_CONNECTION=mysql,DB_HOST=%(ENV_DB_HOST)s,DB_DATABASE=%(ENV_DB_DATABASE)s,DB_USERNAME=%(ENV_DB_USERNAME)s,DB_PASSWORD=%(ENV_DB_PASSWORD)s

Is there an error in the syntax used within the supervisor.conf file? Could there be an issue with how Docker passes environment variables to supervisor.conf?

dark4igi commented 10 months ago

hi @ronyantonydev try to add env variable on execution stage instead of building stage and mount file supervisor.conf instead of coping