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:
1.11.1, build 5604cbe
(1.11.1-0~xenial
)1.7.0, build 0d7bf73
Docker compose located in ~/bin/docker-compose
.
Thanks!
This build should output:
testing
https://travis-ci.org/ujovlado/docker-compose-test/builds/127832493
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"
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
: