title: Docker Compose - How to store database data?
body: <p>I am new to docker and developing a project using docker compose. From the documentation I have learned that I should be using data only containers to keep data persistant but I am unable to do so using docker-compose. 
  Whenever I do <code>docker-compose down</code> it removes the the data from db but by doing <code>docker-compose stop</code> the data is not removed. May be this is because that I am not creating named data volume and <code>docker-compose down</code> hardly removes all the containers. So I tried naming the container but it threw me errors.
  Please have a look at my <code>yml</code> file:</p>
  
  <pre><code>version: '2'
  services: 
     data_container:
       build: ./data
       #volumes:
       #  - dataVolume:/data
    db:
      build: ./db
      ports:
        - "5445:5432"
      environment:
        - POSTGRES_USER=postgres
        - POSTGRES_DB=postgres
      #   - PGDATA=/var/lib/postgresql/data/pgdata
      volumes_from:
       # - container:db_bus
         - data_container
    geoserver:
      build: ./geoserver
      depends_on:
        - db
      ports:
        - "8004:8080"
      volumes:
        - ./geoserver/data:/opt/geoserverdata_dir
  
    web:
      build: ./web
      volumes:
        - ./web:/code
      ports:
        - "8000:8000"
      depends_on:
        - db
      command: python manage.py runserver 0.0.0.0:8000
  
    nginx:
      build: ./nginx
      ports:
        - "83:80"
      depends_on:
        - web
  </code></pre>
  
  <p>The Docker file for the data_container is:</p>
  
  <pre><code>FROM stackbrew/busybox:latest
  MAINTAINER Tom Offermann &lt;tom@offermann.us&gt;
  
  # Create data directory
  RUN mkdir /data
  
  # Create /data volume
  VOLUME /data
  </code></pre>
  
  <p>I tried this but by doing docker-compose down, the data is lost. I tried naming the data_container as you can see the commented line, it threw me this error: </p>
  
  <pre><code>ERROR: Named volume "dataVolume:/data:rw" is used in service "data_container" but no declaration was found in the volumes section.
  </code></pre>
  
  <p>So right now what I am doing is I created a stand alone data only named container and put that in the <code>volumes_from</code> value of the db. It worked fine and didn't remove any data even after doing <code>docker-compose down</code>.</p>
  
  <p><strong>My queries:</strong></p>
  
  <ul>
  <li><p>What is the best approach to make containers that can store database's data using the <code>docker-compose</code> and to use them properly ?</p></li>
  <li><p>My conscious is not agreeing with me on approach that I have opted, the one by creating a stand alone data container. Any thoughts?</p></li>
  </ul>