title: docker-compose: postgres data not persisting
body: <p>I have a main service in my <code>docker-compose</code> file that uses <code>postgres</code>'s image and, though I seem to be successfully connecting to the database, the data that I'm writing to it is not being kept beyond the lifetime of the container (what I did is based on <a href="http://www.andreagrandi.it/2015/02/21/how-to-create-a-docker-image-for-postgresql-and-persist-data/" rel="nofollow">this tutorial</a>).</p>
  
  <p>Here's my <code>docker-compose</code> file:</p>
  
  <pre><code>main:
    build: .
    volumes:
      - .:/code
    links:
      - postgresdb
    command: python manage.py insert_into_database
    environment:
      - DEBUG=true
  
  
  postgresdb:
    build: utils/sql/
    volumes_from:
      - postgresdbdata
    ports:
      - "5432"
    environment:
      - DEBUG=true
  
  
  postgresdbdata:
    build: utils/sql/
    volumes:
      - /var/lib/postgresql
    command: true
    environment:
      - DEBUG=true
  </code></pre>
  
  <p>and here's the Dockerfile I'm using for the <code>postgresdb</code> and <code>postgresdbdata</code> services (which essentially creates the database and adds a user):</p>
  
  <pre><code>FROM postgres
  
  ADD make-db.sh /docker-entrypoint-initdb.d/
  </code></pre>
  
  <p>How can I get the data to stay after the <code>main</code> service has finished running, in order to be able to use it in the future (such as when I call something like <code>python manage.py retrieve_from_database</code>)? Is <code>/var/lib/postgresql</code> even the right directory, and would <code>boot2docker</code> have access to it given that it's apparently limited to <code>/Users/</code>?</p>
  
  <p>Thank you!</p>