Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker compose doesn't recognize 'env_file'

Tags:

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.

like image 501
Dov Benyomin Sohacheski Avatar asked Jun 23 '16 04:06

Dov Benyomin Sohacheski


2 Answers

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

like image 166
Dov Benyomin Sohacheski Avatar answered Sep 28 '22 03:09

Dov Benyomin Sohacheski


I got this issue because I wasn't running $docker-compose up from the same directory as my .env and docker-compose.yml file. The command can still find the docker-compose.yml file, through a search, but it doesn't also search that location for the .env file.

like image 44
mikeLundquist Avatar answered Sep 28 '22 02:09

mikeLundquist