0

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

so it is not possible to mount to current sub directory?
it is but you are using it wrong. first part is host directory, the second part is containers. ./postgres:/var/lib/postgresql

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.