Compose: env_file is ignored and not validated when no .env is present

Created on 10 Nov 2016  路  2Comments  路  Source: docker/compose

According to the documentation for env_file, a file relative to the referencing docker-compose.yml should be read by compose. However it looks like env_file is ignored completely until a .env file is present. When .env is present, the referenced env_file existence is validated, but the contents of the referenced env_file are still being ignored.

Docker for windows
docker-compose version 1.8.1, build 004ddae
Docker version 1.12.3, build 6b644ec

# docker-compose.yml
version: '2'
services:    
    db:
        env_file: conf.env
        image: mariadb
        ports:
            - "$DB_PORT:3306"
        environment:
            - MYSQL_ROOT_PASSWORD=$DB_MYSQL_ROOT_PASSWORD
# conf.env    
DB_PORT=13306
DB_MYSQL_ROOT_PASSWORD=the-root-password



md5-7b37b96088f01af7d4d79fdfda324fa6



$ ls -la
total 14
drwxr-xr-x 1    0 Nov 10 16:40 ./
drwxr-xr-x 1    0 Nov 10 16:39 ../
-rw-r--r-- 1   55 Nov 10 16:40 conf.env
-rw-r--r-- 1  216 Nov 10 16:40 docker-compose.yml

$ docker-compose.exe -p envfile up
The DB_MYSQL_ROOT_PASSWORD variable is not set. Defaulting to a blank string.
The DB_PORT variable is not set. Defaulting to a blank string.
The Compose file '.\docker-compose.yml' is invalid because:
services.db.ports is invalid: Invalid port ":3306", should be [[remote_ip:]remote_port[-remote_port]:]port[/protocol]



md5-4f460e7db3c224656a1bf9aab3321585



$ docker-compose.exe -p envfile up
The DB_MYSQL_ROOT_PASSWORD variable is not set. Defaulting to a blank string.
The DB_PORT variable is not set. Defaulting to a blank string.
The Compose file '.\docker-compose.yml' is invalid because:
services.db.ports is invalid: Invalid port ":3306", should be [[remote_ip:]remote_port[-remote_port]:]port[/protocol]



md5-1fd1681c2d10dde1da23ac09b894ef5b



$ cp conf.env .env
$ docker-compose.exe -p envfile up
Couldn't find env file: C:\tmp\docker\THERE-IS-NO-conf.env

Reverting back to env_file: conf.env appears to be working, since the file exists, but the contents of conf.env are still ignored and read from .env instead.

areconfig kinquestion

Most helpful comment

Ok, so it is an usage error on my side. The missing environment variable errors were hiding the expected missing env_file error. Thanks for clearing that up, shin-.
By looking at other bug reports and some StackOverflow questions I would say the environment variable subject leads to confusion quite often. Maybe link the disambiguation page from the general compose-file page to foolproof things up?

All 2 comments

The .env file and the env_file key are two different things. Please see the disambiguation page for more information.

Ok, so it is an usage error on my side. The missing environment variable errors were hiding the expected missing env_file error. Thanks for clearing that up, shin-.
By looking at other bug reports and some StackOverflow questions I would say the environment variable subject leads to confusion quite often. Maybe link the disambiguation page from the general compose-file page to foolproof things up?

Was this page helpful?
0 / 5 - 0 ratings