patterndockerMinor
Why is environment variable mangled in docker compose environment file
Viewed 0 times
whyfiledockermangledenvironmentcomposevariable
Problem
Context: docker-compose to start several containers, including Gunicorn that calls a Flask app. I'm using an environment file
The problem is that
The question is, where in my setup are my assumptions wrong, thereby causing the environment variable to be mangled? The environment variable is accepted when run manually in a terminal. The docker compose file looks as follows
web/env.gunicorn to store my Gunicorn startup configuration. This file containsGUNICORN_CMD_ARGS="--bind=127.0.0.1:8001 --workers=3"The problem is that
GUNICORN_CMD_ARGS is not processed correctly somewhere in the pipeline. The error that I get when running docker logs gunicorn isError: '8001 --workers=3' is not a valid port number.The question is, where in my setup are my assumptions wrong, thereby causing the environment variable to be mangled? The environment variable is accepted when run manually in a terminal. The docker compose file looks as follows
version: "3"
services:
# nginx:
# image: nginx:latest
# ports:
# - "80:80"
# volumes:
# - ./nginx:/etc/nginx/conf.d
# depends_on:
# - web
web:
build: ./web
container_name: gunicorn
ports:
- "8001:8001"
environment:
- APP_CONFIG_FILE=../config/development.py
env_file:
- 'web/env.gunicorn'
networks:
- backend
command: gunicorn thymedata:app
depends_on:
- influxdb
- grafana
influxdb:
image: influxdb:latest
container_name: influxdb
ports:
- "8086:8086"
env_file:
- 'influxdb/env.influxdb'
- 'influxdb/secrets.influxdb'
networks:
- backend
volumes:
- influxdb-data:/var/lib/influxdb
grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- "3000:3000"
env_file:
- 'grafana/env.grafana'
- 'grafana/secrets.grafana'
networks:
- backend
volumes:
- grafana-data:/var/lib/grafana
depends_on:
- influxdb
networks:
backend:
volumes:
influxdb-data:
grafana-data:Solution
I had a similar problem and this worked for me without it feeling like a hack...
docker-compose.yml:
Note: add env GUNICORN_CMD_ARGS without quotes
Dockerfile:
Note: run CMD gunicorn app:app without passing options via array or quotes
docker-compose.yml:
version: '3'
services:
web:
build .
environment:
- GUNICORN_CMD_ARGS=--workers=0 --bind=0.0.0.0:8000 --timeout=10Note: add env GUNICORN_CMD_ARGS without quotes
Dockerfile:
FROM python:3.6-slim
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
ENV GUNICORN_CMD_ARGS="--bind=0.0.0.0:8000 --workers=3"
CMD gunicorn app:appNote: run CMD gunicorn app:app without passing options via array or quotes
Code Snippets
version: '3'
services:
web:
build .
environment:
- GUNICORN_CMD_ARGS=--workers=0 --bind=0.0.0.0:8000 --timeout=10FROM python:3.6-slim
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
ENV GUNICORN_CMD_ARGS="--bind=0.0.0.0:8000 --workers=3"
CMD gunicorn app:appContext
StackExchange DevOps Q#2980, answer score: 3
Revisions (0)
No revisions yet.