title: How to properly deal with .env files in docker
body: <p>I have a node app using <code>dotenv</code> to keep track of env variables. Its using the <code>.env</code> file in the root folder to get the variables in runtime. The problem is when i'm using docker to build a node image the below line copies the <code>.env</code> file for the build as well</p>
  
  <pre><code>FROM node:latest
  
  # Create app directory
  RUN mkdir -p /usr/src/app
  WORKDIR /usr/src/app
  
  # Install app dependencies
  COPY package.json /usr/src/app/
  RUN npm install
  
  # Bundle app source
  COPY . /usr/src/app
  
  EXPOSE 8000
  </code></pre>
  
  <p>If i build  &amp; pull the image from dockerhub. The file already contains the <code>.env</code> file i used in development. Ideally , i would like to specify a different <code>.env</code> file for production. (perhaps manually creating a new .env file in the production server)</p>
  
  <p>i tried specifying the <code>.env</code> file in dockerignore . but line <code>COPY . /usr/src/app</code> still seems to copy the env file as well.</p>
  
  <p>I do not need to use <code>dotenv</code> as such. I tried specifying it like the below</p>
  
  <pre><code>version: '2'
  
  services:
    node:
      container_name: node
      build: .
      env_file: .env
      volumes:
        - .:/usr/src/app
        - /usr/src/app/node_modules
      command: npm start
  </code></pre>
  
  <p>so i really dont need to specify a .env folder in the build. But this doesnt work as well.</p>
  
  <p>How do i stop the <code>COPY</code> command from copying the <code>.env</code> file?</p>