Docker compose无法识别'env_file' [英] Docker compose doesn't recognize 'env_file'
问题描述
我正在尝试使用以下配置运行docker-compose up
:
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
我在同一目录中有一个.env
文件,并且能够在shell中测试该变量,但是docker似乎没有加载.env
.
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
.
警告:未设置APP_URL变量.默认为空字符串.
WARNING: The APP_URL variable is not set. Defaulting to a blank string.
警告:未设置DB_PASSWORD变量.默认为空字符串.
WARNING: The DB_PASSWORD variable is not set. Defaulting to a blank string.
警告:未设置DB_DATABASE变量.默认为空字符串.
WARNING: The DB_DATABASE variable is not set. Defaulting to a blank string.
警告:未设置DB_USERNAME变量.默认为空字符串.
WARNING: The DB_USERNAME variable is not set. Defaulting to a blank string.
错误:文件'./docker-compose.yaml'中的验证失败
ERROR: Validation failed in file './docker-compose.yaml'
更新
我只是将env_file
值更改为指向不存在的文件,并且没有引发任何错误.似乎docker完全忽略了该选项.
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.
推荐答案
与其他许多与版本相关的问题一样,更新为 docker-compose 的 v1.7.1 解决了该问题,就像魅力一样!
Like many other version related issues, updating to v1.7.1 of docker-compose resolved the issue, works like a charm!
这篇关于Docker compose无法识别'env_file'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!