Here's my compose file 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"
The environment inside the dev.yml file is intentional, so I can override them inside with dev.env if needed.
My dev.env file, located inside compose/fumio_dev/ folder, relative to the dev.yml file.
GIRLFRIEND_FUMIO_PORT=8000
Here's what happens when I run docker-compose -f dev.yml build

If I provide .env file in the root folder, it runs fine, docker-compose ignores the env_file's value and try to use the default .env instead. So docker-compose env_file is somehow not working as intended or I'm missing something?
My docker-compose version is 1.8.0, I downgraded it to 1.7.1 but still no luck (installed using pip).
The .env file in the project root, and the env_file: field in the Compose file are two different concepts.
The .env is for settings a default environment for Compose. Values set in this file can be used within the Compose file.
The env_file: field is for setting the default environment for a container. Values set in this can be used in the container, but not in the Compose file.
See https://docs.docker.com/compose/env-file/ for more information.
As @dnephin has explained,
The env_file: field is for setting the default environment for a container. Values set in this can be used in the container, but not in the Compose file.
And one more thing I'd like to notice is that the --env-file flag that you can specify when executing the command, e.g. docker-compose --env-file ./somefile, and the env_file option in the compose file are absolutely different, too.
The --env-file flag enables you to determine a custom environment file that can be used in your Compose file.
So in your case, I think this command will do the trick:
docker-compose --env-file ./compose/fumio_dev/dev.env -f dev.yml build
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With