Georg Heiler
Georg Heiler

Reputation: 17676

docker-compose postgresql persitent local storage

How can I setup postgresql in docker to be persistent into a local folder?

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

This will not work and yield only

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.

Upvotes: 0

Views: 922

Answers (1)

Farhad Farahi
Farhad Farahi

Reputation: 39237

You need to use absolute mount path, ./postgres should be changed.

Upvotes: 1

Related Questions