title: Why isn't my PostgreSQL data persistent in Docker using volumes?
body: <p>I am currently learning how to use Flask, PostgreSQL and Docker because I am trying to do a web app.</p>
  <p>I have created two containers for the development phase: one for the database and other one for the web. The problem that I have is that whenever I stop and restart my containers, the data is not there anymore.</p>
  <p>For the creation of the containers I have followed the following link: <a href="https://testdriven.io/blog/dockerizing-flask-with-postgres-gunicorn-and-nginx/#project-setup" rel="nofollow noreferrer">https://testdriven.io/blog/dockerizing-flask-with-postgres-gunicorn-and-nginx/#project-setup</a></p>
  <p>I have seen that I could create a volume to persist the data in the container but it doesn't seem to work and I don't really understand why. Here is my docker-compose file:</p>
  <pre><code>version: '3.7'
  
  services:
   web:
     build: ./services/web
     restart: always
     command: python manage.py run -h 0.0.0.0
     volumes:
       - ./services/web/:/usr/src/app/
       - ./migrations:/usr/src/app/migrations
     ports:
       - 5000:5000
     env_file:
       - ./dev.env
     depends_on:
       - db
   db:
     container_name: postgres
     restart: always
     image: postgres:latest
     volumes:
       - pgdata:/var/lib/postgresql/data
       - .:/usr/src/app #For refreshing the container if the code changes
     ports: 
       - 5432:5432
     environment:
       - POSTGRES_USER=hello_flask
       - POSTGRES_PASSWORD=hello_flask
       - POSTGRES_DB= hello_flask_dev #To change
  
  volumes:
   pgdata:
  </code></pre>
  <p>I am careful to use <code> docker-compose up -d</code> so I don't remove any volume and the following volume is created seen with <code>docker volume inspect</code>:</p>
  <pre><code>[
      {
          &quot;CreatedAt&quot;: &quot;2021-04-19T13:19:05Z&quot;,
          &quot;Driver&quot;: &quot;local&quot;,
          &quot;Labels&quot;: {
              &quot;com.docker.compose.project&quot;: &quot;hera_docker&quot;,
              &quot;com.docker.compose.version&quot;: &quot;1.29.0&quot;,
              &quot;com.docker.compose.volume&quot;: &quot;pgdata&quot;
          },
          &quot;Mountpoint&quot;: &quot;/var/lib/docker/volumes/hera_docker_pgdata/_data&quot;,
          &quot;Name&quot;: &quot;hera_docker_pgdata&quot;,
          &quot;Options&quot;: null,
          &quot;Scope&quot;: &quot;local&quot;
      }
  ]
  </code></pre>
  <p>I would like to maintain the docker-compose commands because the two containers are together in a multicontainer.</p>
  <p>Any help will be of great help. I have checked some other questions in this forum but I don't really know what's going on that mine doesn't work.</p>
  <p>Thanks in advance.</p>