Why is environment variable mangled in docker compose environment file Context: docker-compose to start several containers, including Gunicorn that calls a Flask app. I'm using an environment file web/env.gunicorn to store my Gunicorn startup configuration. This file contains

GUNICORN_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 is

Error: '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:
I had a similar problem and this worked for me without it feeling like a hack...

docker-compose.yml:

version: '3'
services:
   web:
      build .
      environment:
      - GUNICORN_CMD_ARGS=--workers=0 --bind=0.0.0.0:8000 --timeout=10


Note: 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:app


Note: run CMD gunicorn app:app without passing options via array or quotes