Named volume with postgresql doesn't keep database's data

Hi all,

I have the following docker-compose.yml with the app & nginx containers removed:

version: '2'
services:
  postgres:
    restart: always
    image: postgres:latest
    volumes:
      - dbdatavol:/var/lib/postgresql
    ports:
      - "5433:5432"
volumes:
  dbdatavol:
    driver: local

When I bring this up with docker-compose, and run the commands to create the database, everything works fine. But after bringing it down, and back up, the data is gone from the database. I’ve touched a file in the volume, and it is still there, but using psql to login to the server, all the tables have been removed. Anyone know what I’m doing wrong? docker v. 1.10.3, and docker-compose 1.6.2

For posterity: the answer was that the postgres image creates a volume specifically on the sub-directory /var/lib/postgresql/data. Changing my volume to reference that directory kept the database alive between ups and downs.

3 Likes