docker-compose postgresql persitent本地存储

我如何在docker中设置postgresql来持久化到本地文件夹?

version: '2' services: db: image: postgres:9.6.1-alpine ports: - "5432:5432" environment: - POSTGRES_USER=a - POSTGRES_PASSWORD=a - POSTGRES_DB=a volumes: - /var/lib/postgresql:./postgres volumes: pgdata: driver: local 

这不会工作,只有产量

 ERROR: for db Cannot create container for service db: invalid volume spec "postgres": invalid volume specification: 'postgres': invalid mount config for type "volume": invalid mount path: 'postgres' mount path must be absolute ERROR: Encountered errors while bringing up the project. 

你需要使用绝对安装path,./ ./postgres应该被改变。