title: ENV variables not coming through godotenv Docker
body: <p>I have a web app written in Go, dockerised and using gomod.</p>
  <p>I cannot get it to read environment variables.</p>
  <p>Upon running docker-compose up always returns &quot;Error getting env, not comming through&quot;</p>
  <p>I'm using godotenv to try do this. Below is my implementation. I cannot for the life of me figure out what's going wrong. If anyone can see something I'm missing you'll be saving a life.</p>
  <p><em>The main.go, .env, docker-compose.yml and Dockerfile are all in the root of the project</em></p>
  <p><strong>main.go</strong></p>
  <pre><code>func main() {
      router := mux.NewRouter()
  
      err := godotenv.Load()
      if err != nil {
          log.Fatalf(&quot;Error getting env, not comming through %v&quot;, err)
      } else {
          fmt.Println(&quot;We are getting the env values&quot;)
      }
  
      fmt.Println(os.Getenv(&quot;MY_ENV&quot;))
  
  }
  </code></pre>
  <p><strong>.env</strong></p>
  <pre><code>MY_ENV=thisismyenvvariable
  DB_HOST=testdata123
  DB_DRIVER=testdata123
  DB_USER=&quot;testdata123&quot;
  DB_PASSWORD=testdata123
  DB_NAME=testdata123
  DB_PORT=5432
  
  </code></pre>
  <p><strong>docker-compose.yml</strong></p>
  <pre><code>version: '3'
  services:
    app:
      container_name: template_123
      build: .
      ports: 
        - 8080:8080 
      restart: on-failure
      volumes:
        - api:/usr/src/app/
      env_file:
        - .env
      depends_on:
        - template-postgres          
      networks:
        - template
  
  
    template-postgres:
      image: postgres:latest
      container_name: startup_template_golang_db_postgres
      environment:
        - POSTGRES_USER=${DB_USER}  
        - POSTGRES_PASSWORD=${DB_PASSWORD}
        - POSTGRES_DB=${DB_NAME}
        - DATABASE_HOST=${DB_HOST} 
      ports:
        - '5432:5432'
      volumes:
        - database_postgres:/var/lib/postgresql/data
      env_file:
        - .env
      networks:
        - template
      
    pgadmin:
      image: dpage/pgadmin4
      container_name: pgadmin_container
      environment:
        PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
        PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
      depends_on:
        - template-postgres
      ports:
        - &quot;5050:80&quot;
      networks:
        - template
      restart: unless-stopped
  
  volumes:
    api:
    database_postgres:                  
  
  # Networks to be created to facilitate communication between containers
  networks:
    startup_template:
      driver: bridge
  </code></pre>
  <p><strong>Dockerfile</strong></p>
  <pre><code># Start from golang base image
  FROM golang:alpine as builder
  
  # ENV GO111MODULE=on
  
  # Add Maintainer info
  LABEL maintainer=&quot;satoshi123&quot;
  
  # Install git.
  # Git is required for fetching the dependencies.
  RUN apk update &amp;&amp; apk add --no-cache git
  
  # Set the current working directory inside the container 
  WORKDIR /app
  
  # Copy go mod and sum files 
  COPY go.mod go.sum ./
  
  # Download all dependencies. Dependencies will be cached if the go.mod and the go.sum files are not changed 
  RUN go mod download 
  
  # Copy the source from the current directory to the working Directory inside the container 
  COPY . .
  
  # Build the Go app
  RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
  
  # Start a new stage from scratch
  FROM alpine:latest
  RUN apk --no-cache add ca-certificates
  
  WORKDIR /root/
  
  # Copy the Pre-built binary file from the previous stage. Observe we also copied the .env file
  COPY --from=builder /app/main .
  # COPY --from=builder /app/.env .       
  
  # Expose port 8080 to the outside world
  EXPOSE 8080
  
  #Command to run the executable
  CMD [&quot;./main&quot;]
  </code></pre>