I have a .env file like below:
# DEV
SALES_DB_HOST=xxx
Then I have a docker-compose.yml file that looks like:
version: "3.1"
services:
  web:
    image: xxx
    build: .
    env_file: .env
However, the values for the environment variables when accessed in nodejs like process.env.SALES_DB_HOST it prints undefined.
Output of docker-compose config is:
services:
  web:
    build:
      context: xxxxxxxx
    environment:
      SALES_DB_HOST: xxx
    image: xxxxx
version: '3.1'
So, it looks like docker-compose.yml is formed correctly. But why is process.env not getting this value correctly?
EDIT:
I build the docker image with: docker build -t my_image .
 
    