Compose: .env file ignored

Created on 4 May 2016  路  7Comments  路  Source: docker/compose

Hi, I'm running docker-compose and .env file is ignored.

Location of the files:

$ ls -la | grep -e ".env" -e "docker-compose.yml"
-rw-rw-r--  1 vlado vlado   2878 May  4 17:17 docker-compose.yml
-rw-rw-r--  1 vlado vlado    171 May  4 16:42 .env

Environment:

  • engine: 1.11.1, build 5604cbe (1.11.1-0~xenial)
  • compose: 1.7.0, build 0d7bf73

Docker compose located in ~/bin/docker-compose.

Thanks!

Most helpful comment

If you want the environment variables to turn up inside the container, you have to explicitly pass them through in docker-compose.yml:

version: "2"

services:
  nothing:
    image: debian:jessie
    command: /bin/false
    environment:
      - FOO

All 7 comments

The .env file has to be present in the working directory. Could that be the issue you're seeing?

https://gist.github.com/rafaelsierra/1b27afbea0a992a7518807c6e6079167

The .env file is on the same folder as everything else

Those environment variables will be used for variable substitution in your Compose file, but can also be used to define the following CLI variables:
From https://docs.docker.com/compose/env-file/

If that means that the .env file is used only for variable substitution then it is safe to ignore my comments

If you want the environment variables to turn up inside the container, you have to explicitly pass them through in docker-compose.yml:

version: "2"

services:
  nothing:
    image: debian:jessie
    command: /bin/false
    environment:
      - FOO

Comment by @aanand solved my problem. Thanks :+1:

I just want to comment on this, because I keep forgetting it.

Not only do you need to set the env names in docker-compose.yml like this:

services:
  my_service:
    environment:
      - FOO

You also need to write the value in the .env file without quotes:

# this works
FOO=bar

# this doesn't work
FOO="bar"
Was this page helpful?
0 / 5 - 0 ratings

Related issues

dazorni picture dazorni  路  3Comments

CrimsonGlory picture CrimsonGlory  路  3Comments

leiblix picture leiblix  路  3Comments

saulshanabrook picture saulshanabrook  路  3Comments

DhairyashilBhosale picture DhairyashilBhosale  路  3Comments