title: Why does variables substitution not work when using multiple env_files in docker-compose.yml?
body: <p>I'm trying to get a docker-compose file working with multiple <code>.env</code> files, and I'm not having any luck.  I'm trying to setup three <code>.env</code> files:</p>
  
  <ul>
  <li>global settings that are the same across all container instances</li>
  <li>environment-specific settings (stuff just for test or dev)</li>
  <li>local settings - overridable things that a developer might need to change in case they have conflicts with, say, a port number</li>
  </ul>
  
  <p>My <code>docker-compose.yml</code> file looks like this:</p>
  
  <pre><code>version: '2'
  services:
    db:
      env_file:
        - ./.env
        - ./.env.${ENV}
        - ./.env.local
      image: postgres
      ports:
        - ${POSTGRES_PORT}:5432
  </code></pre>
  
  <p><code>.env</code> looks like this:</p>
  
  <pre><code>POSTGRES_USER=myapp
  </code></pre>
  
  <p>and the <code>.env.development</code> looks like this:</p>
  
  <pre><code>POSTGRES_PASSWORD=supersecretpassword
  POSTGRES_HOST=localhost
  POSTGRES_PORT=25432
  POSTGRES_DB=myapp_development
  </code></pre>
  
  <p><code>.env.local</code> doesn't exist in this case.</p>
  
  <p>After running <code>ENV=development docker-compose up</code>, I receive the following output:</p>
  
  <pre><code>$ ENV=development docker-compose up
  WARNING: The POSTGRES_PASSWORD variable is not set. Defaulting to a blank string.
  WARNING: The POSTGRES_DB variable is not set. Defaulting to a blank string.
  WARNING: The POSTGRES_PORT variable is not set. Defaulting to a blank string.
  ERROR: The Compose file './docker-compose.yml' is invalid because:
  services.db.ports is invalid: Invalid port ":5432", should be [[remote_ip:]remote_port[-remote_port]:]port[/protocol]
  </code></pre>
  
  <p>From that error message, it looks like none of my environment variables are being used.  I just upgraded to the newest available docker-compose as well - same errors:</p>
  
  <pre><code>$ docker-compose --version
  docker-compose version 1.8.0-rc1, build 9bf6bc6
  </code></pre>
  
  <p>Any ideas here?  Would be nice to have a single <code>docker-compose.yml</code> that would work across multiple environments.</p>