Docker Community Forums

Share and learn in the Docker community.

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

(Foxwoodswebsites) #1

Hi all,

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

version: '2'
    restart: always
    image: postgres:latest
      - dbdatavol:/var/lib/postgresql
      - "5433:5432"
    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

(Foxwoodswebsites) #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.