Docker compose doesn't recognize 'env_file'

馋奶兔 提交于 2019-12-23 15:25:20

问题


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.


回答1:


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




回答2:


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.




回答3:


Suggest you to use Volumes also.. otherwise when the DB container is deleted or upgraded.. you will loose all you DB data. :) Do not pass ENV with sensitive data to the NGINX.. You missing also the link in the FPM to the DB.



来源:https://stackoverflow.com/questions/37982317/docker-compose-doesnt-recognize-env-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!