Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"env_file" not working in Windows 10 #6965

Closed
nighttiger1990 opened this issue Oct 16, 2019 · 7 comments
Closed

"env_file" not working in Windows 10 #6965

nighttiger1990 opened this issue Oct 16, 2019 · 7 comments

Comments

@nighttiger1990
Copy link

nighttiger1990 commented Oct 16, 2019

Description of the issue

I declare env_file property with value deploy.env in docker-compose.yml.
But when docker compose up in Windows deploy.env file not read

Context information (for bug reports)

Output of docker-compose version

docker-compose version 1.24.1, build 4667896b
docker-py version: 3.7.3
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.0.2q  20 Nov 2018

Output of docker version

Client: Docker Engine - Community
 Version:           19.03.2
 API version:       1.40
 Go version:        go1.12.8
 Git commit:        6a30dfc
 Built:             Thu Aug 29 05:26:49 2019
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.2
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.8
  Git commit:       6a30dfc
  Built:            Thu Aug 29 05:32:21 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.6
  GitCommit:        894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc:
  Version:          1.0.0-rc8
  GitCommit:        425e105d5a03fabd737a126ad93d62a9eeede87f
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Output of docker-compose config
(Make sure to add the relevant -f and other flags)

WARNING: The DB_HOST variable is not set. Defaulting to a blank string.
networks:
  notif-v2-production:
    driver: bridge
services:
  mongo-docker:
    container_name: ''
    environment:
      DB_DATABASE: ''
      DB_HOST: notif-mongodb-test
      DB_PASSWORD: ''
      DB_PORT: '27017'
      DB_USERNAME: ''
      DEBUG: '"notification-server-v2:*"'
      MESSAGE: '"THIS IS MY MESSAGE"'
    image: mongo:4.2.0
    networks:
      notif-v2-production: null
    restart: unless-stopped
    volumes:
    - D:\Project\NodeJS\notification-server-v2\data:/data/db:rw
  notification-server-v2:
    container_name: notification-server-v2
    depends_on:
    - mongo-docker
    environment:
      DB_DATABASE: ''
      DB_HOST: notif-mongodb-test
      DB_PASSWORD: ''
      DB_PORT: '27017'
      DB_USERNAME: ''
      DEBUG: '"notification-server-v2:*"'
      MESSAGE: '"THIS IS MY MESSAGE"'
    image: notification-server-v2
    networks:
      notif-v2-production: null
    ports:
    - published: 3000
      target: 3000
    restart: unless-stopped
version: '3.7'

Steps to reproduce the issue

  1. deploy.env file same location with docker-compose.yml
  2. run docker compose -f docker-compose up -d
  3. On Windows 10, message get The DB_HOST variable is not set. Defaulting to a blank string
    But on Centos 7 work perfectly
    Additional: if i change deploy.env to .env Windows work perfectly

Additional information

My deploy.env

DB_HOST=notif-mongodb-test
DB_PORT=27017
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=

MESSAGE="THIS IS MY MESSAGE"

DEBUG="notification-server-v2:*"

My docker-compose.yml

version: '3.7'

services:
  notification-server-v2:
    container_name: notification-server-v2
    image: notification-server-v2
    env_file: deploy.env
    ports:
      - 3000:3000
    networks: 
      - notif-v2-production
    restart: unless-stopped
    depends_on:
      - mongo-docker
  mongo-docker:
    container_name: ${DB_HOST}
    image: mongo:4.2.0
    networks: 
      - notif-v2-production
    restart: unless-stopped
    env_file: deploy.env
    volumes:
      - ./data/${DB_HOST}:/data/db
networks: 
  notif-v2-production:
    driver: bridge

OS version / distribution, docker-compose install method, etc.

@nighttiger1990 nighttiger1990 changed the title "env_file" without not working in Windows 10 "env_file" not working in Windows 10 Oct 16, 2019
@ndeloof
Copy link
Contributor

ndeloof commented Oct 16, 2019

env_file is not used for variable interpolation in the container specification used by compose to create containers, but passed to the docker API as runtime definition for the process runing inside the container.

so container_name: ${DB_HOST} won't get resolved to anything until you have a matching local environment variable or .env file to set a value (see https://docs.docker.com/compose/env-file/).

This is a common source of confusion with compose :P

@hozmaster
Copy link

So it's should resolve to rename .env for more proper name, like .build_env. Of course it would document properly of docker-compose documentation so the env-file is not confused with .env file which is different thing.

@nighttiger1990
Copy link
Author

nighttiger1990 commented Oct 23, 2019

env_file is not used for variable interpolation in the container specification used by compose to create containers, but passed to the docker API as runtime definition for the process runing inside the container.

so container_name: ${DB_HOST} won't get resolved to anything until you have a matching local environment variable or .env file to set a value (see https://docs.docker.com/compose/env-file/).

This is a common source of confusion with compose :P

but when deploying on Centos 7, setting env_file: deploy.env still work
And you see the output docker-compose config i got conflict when get both:

  1. get Warning DB_HOST not set.
  2. get DB_HOST set in environment with value notif-mongodb-test

@stale
Copy link

stale bot commented Apr 20, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 20, 2020
@stale
Copy link

stale bot commented Apr 27, 2020

This issue has been automatically closed because it had not recent activity during the stale period.

@stale stale bot closed this as completed Apr 27, 2020
@mcfriend99
Copy link

I have a local .env file in the same directory as docker-compose.yml, but .env file is still not working

@JonasCir
Copy link

Same here as @nighttiger1990 reported. Exactly the same project setup works flawlessly on Linux, but .env file is not read by docker compose on windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants