title: Docker compose is using the env which was built by Dockerfile, instead of using env_file located in docker-compose.yml directory because of webpack
body: <p>First I want to use my application .env variables on my webpack.config.prod.js, so I did this in my webpack file.</p>
  <p><a href="https://i.stack.imgur.com/JViO9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JViO9.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/ekKJW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ekKJW.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/MIYwl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MIYwl.png" alt="enter image description here" /></a></p>
  <p>I am successfully able to access process.env.BUILD variables.</p>
  <p>My application’s env has this configuration -</p>
  <p><a href="https://i.stack.imgur.com/emlsa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/emlsa.png" alt="enter image description here" /></a></p>
  <p>My nodejs web app is running fine locally, no problem at all. I want to build docker image of this application and need to use docker-compose to create the container.</p>
  <p>I built my docker image and everything good so far.</p>
  <p>now to create container, instead of docker run. I am using separate folder which consists of docker-compose.yml and .env files. Attached the screenshot below</p>
  <p><a href="https://i.stack.imgur.com/vfFaE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vfFaE.png" alt="![enter image description here" /></a></p>
  <p>My docker-compose.yml has this code -</p>
  <pre><code>version: '3.9'
  services:     
    api:
      image: 'api:latest'
      ports:
        - '17000:17000'
      env_file:
        - .env
      volumes:
        - ./logs:/app/logs
      networks:
        - default
  </code></pre>
  <p>My docker-compose .env has this redis details</p>
  <p><a href="https://i.stack.imgur.com/96YSc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/96YSc.png" alt="enter image description here" /></a></p>
  <p> My application has this logs -</p>
  <p><a href="https://i.stack.imgur.com/mPYxU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mPYxU.png" alt="enter image description here" /></a></p>
  <p>I started my docker container by doing docker-compose up. Containers created and up and running, but the problem is</p>
  <p>In the console, after connecting to redis.. process.env.REDIS_HOST contains the value called ‘localhost’ (which came from the first env where I used to build docker image). Docker compose .env is not getting accessed.</p>
  <p>After spending 5+ hours. I found the culprit, It was webpack. On my initial code, I added some env related things in my webpack right? Once I commented those, taken a new build. Everything is working fine.</p>
  <p>But my problem is how I can actually use process.ENV in webpack, also docker-compose need to use the .env from its directory. </p>
  <p>Updated -</p>
  <p>My DockerFile looks like this:</p>
  <p><a href="https://i.stack.imgur.com/HHWIg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HHWIg.png" alt="enter image description here" /></a></p>
  <p>Just, It will copy the dist which contains bundle.js, npm start will do - pm2 run bundle.js.</p>