title: Docker volume doesn't keep data after turned docker-compose down
body: <p>I am using docker compose to combine 2 images (tomcat with my app and database - postgres).</p>
  
  <p>My compose file looks like this :</p>
  
  <pre><code>version: '3'
  
  services:
    tomcat:
      build: ./tomcat-img
      ports:
        - "8080:8080"
      depends_on:
        - "db"
  
    db:
      build: ./db-img
      volumes:
         - db-data:/var/lib/postgres/data
      ports:
        - "5433:5432"
  
  volumes:
    db-data:
  </code></pre>
  
  <p>and here is dockerfile for database image:</p>
  
  <pre><code>FROM postgres:9.5-alpine
  ENV POSTGRES_DB mydb
  ENV POSTGRES_USER xxxx
  ENV POSTGRES_PASSWORD xxxx
  COPY init-db.sql /docker-entrypoint-initdb.d/
  
  EXPOSE 5432
  CMD ["postgres"]
  </code></pre>
  
  <p>Next I started my containers with docker-compose cli <code>docker-compose -f docker-compose.yml up</code></p>
  
  <p>and run psql tool with:</p>
  
  <pre><code>docker exec -it container_id psql -d xxxx -U xxxx
  </code></pre>
  
  <p>and insert new record. After that I check if there really is:</p>
  
  <pre><code>select * from my_table;
  </code></pre>
  
  <p>After that I tried stopped docker compose and remove containers with:</p>
  
  <pre><code>docker-compose -f docker-compose.yml down
  </code></pre>
  
  <p>and start it again</p>
  
  <pre><code>docker-compose -f docker-compose.yml up
  </code></pre>
  
  <p>when I run again psql tool of db container and select data in my_table, there is no previous inserted record ... Can you help me to fix it please? I need init my db with init-db.sql just once and next using that persist storage. Thanks for answers.</p>