简体   繁体   English

Docker撰写无法识别'env_file'

[英]Docker compose doesn't recognize 'env_file'

I am trying to run docker-compose up with the following configuration: 我正在尝试使用以下配置运行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

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

WARNING : The APP_URL variable is not set. 警告 :未设置APP_URL变量。 Defaulting to a blank string. 默认为空字符串。

WARNING : The DB_PASSWORD variable is not set. 警告 :未设置DB_PASSWORD变量。 Defaulting to a blank string. 默认为空字符串。

WARNING : The DB_DATABASE variable is not set. 警告 :未设置DB_DATABASE变量。 Defaulting to a blank string. 默认为空字符串。

WARNING : The DB_USERNAME variable is not set. 警告 :未设置DB_USERNAME变量。 Defaulting to a blank string. 默认为空字符串。

ERROR : Validation failed in file './docker-compose.yaml' 错误 :文件'./docker-compose.yaml'中的验证失败


UPDATE UPDATE

I just changed the env_file value to point to a non-existing file and no errors are thrown. 我刚刚将env_file值更改为指向不存在的文件,并且不会抛出任何错误。 It seems like docker is completely ignoring the option. 似乎docker完全无视选项。

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

Suggest you to use Volumes also.. otherwise when the DB container is deleted or upgraded.. you will loose all you DB data. 建议你也使用Volumes ..否则当数据库容器被删除或升级时......你将丢失所有数据库数据。 :) Do not pass ENV with sensitive data to the NGINX.. You missing also the link in the FPM to the DB. :)不要将带有敏感数据的ENV传递给NGINX ..您还缺少FPM中与DB的链接。

I got this issue because I wasn't running $docker-compose up from the same directory as my .env and docker-compose.yml file. 我遇到了这个问题,因为我没有从与我的.envdocker-compose.yml文件相同的目录运行$docker-compose up .env docker-compose.yml 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. 该命令仍然可以通过搜索找到docker-compose.yml文件,但它也不会搜索.env文件的该位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM