Lion
Lion

Reputation: 17879

env_file is ignored in docker-compose and cause "The ... variable is not set" warning

I simply want to use a environment variable loaded from file in my docker-compose file. But after running the container, I only got

WARNING: The TESTVAR variable is not set. Defaulting to a blank string.

Only found this topic, but I'm using a later version of docker like there (docker-compose: 1.14.0, docker: 17.05.0-ce). And I changed the encoding to ISO 8859-1, since I found a github issue where strange behavior with encodings was detected. Both doesn't work.

My docker-compose file

version: '2'
services:
  mysql:
    container_name: test_${TESTVAR}
    build: mysql
    mem_limit: 1G
    env_file:
      - credentials.env

credentials.env contains only TESTVAR=test123. To start, I run docker-compose up mysql and I also tried to specify the environment variables directly in the compose file like this:

environment:
  - TESTVAR=1234

Not working, too.

Upvotes: 2

Views: 3410

Answers (1)

Mazel Tov
Mazel Tov

Reputation: 2182

If you want to use variables in the docker-compose.yml you can do it with .env file, docker docs

$ cat .env
TAG=v1.5
TESTVAR=123

$ cat docker-compose.yml
version: '3'
services:
  web:
    image: "webapp:${TAG}"
    environment: ["TESTVAR=${TESTVAR}"]

Upvotes: 0

Related Questions