Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when starting supervisor with environment variables in Docker #1608

Open
ronyantonydev opened this issue Nov 2, 2023 · 1 comment
Open

Comments

@ronyantonydev
Copy link

ronyantonydev commented Nov 2, 2023

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
Copy link

dark4igi commented Feb 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants