docker-compose postgresql persitent local storage

时间:2017-01-21 09:45:02

标签: postgresql docker docker-compose persistent-storage

如何在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.

1 个答案:

答案 0 :(得分:1)

您需要使用绝对装载路径,./postgres应该更改。