5

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

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.

警告:未设置 APP_URL 变量。默认为空字符串。

警告:未设置 DB_PASSWORD 变量。默认为空字符串。

警告:未设置 DB_DATABASE 变量。默认为空字符串。

警告:未设置 DB_USERNAME 变量。默认为空字符串。

错误:文件“./docker-compose.yaml”中的验证失败


更新

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.

4

2 回答 2

3

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

于 2016-06-23T06:20:06.423 回答
1

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.

于 2019-07-16T20:54:07.407 回答