title: Pass environment variable to dockerfile build
body: <p>I am trying to create a service consisting of a web server and database all in docker containers. Currently I am trying to create same environment file for both of them that would contain database credentials. Unfortunatelly, when I try to build database with it, it turns out that they are empty. How can I create a project with single environment file for both components? Here is my docker-compose.yml:</p>
  
  <pre><code>version: '2'
  
  services:
    db:
      build:
        context: .
        dockerfile: Dockerfile-db
      ports:
        - '5433:5432'
      env_file:
        - env
    web:
      build: .
      ports:
        - '8000:8000'
      command: venv/bin/python manage.py runserver 0.0.0.0:8000
      depends_on:
        - db
      env_file:
        - env
  </code></pre>
  
  <p>Here is part of my Dockerfile-db file responsible for creating database:</p>
  
  <pre><code>FROM ubuntu:16.04
  
  RUN apt-get update &amp;&amp; apt-get install -y postgresql-9.5-postgis-2.2
  
  USER postgres
  
  ARG DB_PASSWORD
  ARG DB_NAME
  
  RUN echo $DB_PASSWORD
  
  RUN /etc/init.d/postgresql start &amp;&amp; \
      psql --command "ALTER USER postgres WITH PASSWORD '$DB_PASSWORD';" &amp;&amp; \
      psql --command "CREATE DATABASE $DB_NAME;" &amp;&amp; \
      psql --command "\\c $DB_NAME" &amp;&amp; \
      psql --command "CREATE EXTENSION postgis;" &amp;&amp; \
      psql --command "CREATE EXTENSION postgis_topology;"
  </code></pre>
  
  <p>And my env file has following structure:</p>
  
  <pre><code>DB_NAME=some_name
  DB_USER=postgres
  DB_PASSWORD=some_password
  DB_HOST=db
  DB_PORT=5432
  </code></pre>