title: docker-compose: using multiple Dockerfiles for multiple services
body: <p>I'm using docker-compose and I'd like to use different Dockerfiles for different services' build steps. The <a href="https://docs.docker.com/compose/yml/#build" rel="noreferrer">docs</a> seem to suggest to place different Dockerfiles in different directories, but I'd like them all to be in the same one (and perhaps distinguishable using the following convention: Dockerfile.postgres, Dockerfile.main...). Is this possible?</p>
  
  <p><strong>Edit:</strong> The scenario I have contains this docker-compose file:</p>
  
  <pre><code>main:
    build: .
    volumes:
      - .:/code
    environment:
      - DEBUG=true
  
  postgresdb:
    extends:
      file: docker-compose.yml
      service: main
    build: utils/sql/
    ports:
      - "5432"
    environment:
      - DEBUG=true
  </code></pre>
  
  <p>where <code>postgresdb</code>'s Dockerfile is:</p>
  
  <pre><code>FROM postgres
  
  # http://www.slideshare.net/tarkasteve/developerweek-2015-docker-tutorial
  ADD make-db.sh /docker-entrypoint-initdb.d/
  </code></pre>
  
  <p>and the main is:</p>
  
  <pre><code>FROM python:2.7
  
  RUN mkdir /code
  WORKDIR /code
  ADD requirements.txt /code/
  
  RUN pip install --upgrade pip
  RUN pip install -r requirements.txt
  ADD . /code/
  </code></pre>
  
  <p>This works right now, but I'd like to extend <code>postgresdb</code>'s Dockerfile by calling a Python script that creates tables in the database according to models built upon SQL Alchemy (the Python script would be called as <code>python manage.py create_tables</code>). I wanted to add it to the db's Dockerfile, but due to the isolation of the containers I can't use SQL Alchemy there because that image is based on the <code>postgres</code> image instead of Python's, and it doesn't contain the <code>sqlalchemy</code> package...</p>
  
  <p>What can I do? I tried to use the <code>main</code> service in <code>postgresdb</code>, but unfortunately it doesn't carry python and its packages over, so I still can't write a single Dockerfile that creates the Postgres database (through the shell script) as well as its tables (through a Python script).</p>