Docker撰写无法识别’env_file’

我正在尝试使用以下配置运行docker-compose:

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

我在同一目录中有一个.env文件,并且能够测试shell中的变量,但是docker似乎没有加载.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

我刚刚将env_file值更改为指向不存在的文件,并且不会抛出任何错误.似乎docker完全无视选项.

最佳答案 像许多其他版本相关的问题一样,更新到docker-compose的v1.7.1解决了这个问题,就像一个魅力!

点赞