Search code examples
dockerenvironment-variablesdocker-composedockerfiledocker-build

Docker compose doesn't recognize 'env_file'


I am trying to run docker-compose up with the following configuration:

php:
    image: php:7.0-fpm
    expose:
        - 9000
    links:
        - nginx

nginx:
    env_file: .env
    image: nginx:latest
    ports:
        - 80:80
        - 433:433
    environment:
        - NGINX_HOST: ${APP_URL}

mysql:
    env_file: .env
    image: mysql:latest
    ports:
        - 3306:3306
    environment:
        - MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
        - MYSQL_DATABASE: ${DB_DATABASE}
        - MYSQL_USER: ${DB_USERNAME}
        - MYSQL_PASSWORD: ${DB_PASSWORD}
        - MYSQL_ALLOW_EMPTY_PASSWORD: no

I have an .env file in the same directory and am able to test the variable in the shell, but docker doesn't seem to load the .env.

WARNING: The APP_URL variable is not set. Defaulting to a blank string.

WARNING: The DB_PASSWORD variable is not set. Defaulting to a blank string.

WARNING: The DB_DATABASE variable is not set. Defaulting to a blank string.

WARNING: The DB_USERNAME variable is not set. Defaulting to a blank string.

ERROR: Validation failed in file './docker-compose.yaml'


UPDATE

I just changed the env_file value to point to a non-existing file and no errors are thrown. It seems like docker is completely ignoring the option.


Solution

  • Like many other version related issues, updating to v1.7.1 of docker-compose resolved the issue, works like a charm!