[英]docker-compose not recognizing env_file file/location, and still tries to use the default .env
這是我的撰寫文件dev.yml
version: '2'
volumes:
rethinkdb_data_dev: {}
services:
rethinkdb:
image: rethinkdb:latest
volumes:
- rethinkdb_data_dev:/home/rethinkdb_data
rabbitmq:
image: rabbitmq:latest
fumio:
build:
context: .
dockerfile: ./compose/fumio_dev/Dockerfile
depends_on:
- rethinkdb
- rabbitmq
links:
- rethinkdb
- rabbitmq
env_file: ./compose/fumio_dev/dev.env
environment:
- GIRLFRIEND_FUMIO_CONFIG=development
- GIRLFRIEND_FUMIO_NOSQLDATABASE_HOST=rethinkdb
ports:
- "${GIRLFRIEND_FUMIO_PORT}:8001"
dev.yml
文件中的environment
是有意的,因此我可以在需要時使用dev.env
覆蓋它們。
我的dev.env
文件位於compose/fumio_dev/
文件夾內,相對於dev.yml
文件。
GIRLFRIEND_FUMIO_PORT=8000
這是我運行docker-compose -f dev.yml build
時發生的情況
如果我在根文件夾中提供.env
文件,它運行良好, env_file
-compose 會忽略env_file
的值並嘗試使用默認的.env
。 所以 docker-compose env_file 不知何故不能按預期工作,或者我遺漏了什么?
我的 docker-compose 版本是 1.8.0,我將它降級到 1.7.1 但仍然沒有運氣(使用 pip 安裝)。
項目根目錄中的.env
文件和Compose文件中的env_file:
字段是兩個不同的概念。
.env
用於設置Compose的默認環境。 可以在Compose文件中使用此文件中設置的值。
env_file:
字段用於設置容器的默認環境。 在此設置的值可以在容器中使用,但不能在Compose文件中使用。
有關更多信息,請參閱https://docs.docker.com/compose/env-file/ 。
正如@dnephin 所解釋的那樣,
env_file: 字段用於設置容器的默認環境。 在此設置的值可以在容器中使用,但不能在 Compose 文件中使用。
我還想注意的另一件事是您可以在執行命令時指定的--env-file
標志,例如docker-compose --env-file ./somefile
,以及撰寫文件中的env_file
選項是也完全不同。
--env-file
標志使您能夠確定可在 Compose 文件中使用的自定義環境文件。
所以在你的情況下,我認為這個命令可以解決問題:
docker-compose --env-file ./compose/fumio_dev/dev.env -f dev.yml build
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.