Mr Mixin
Mr Mixin

Reputation: 913

How do i get postgres data to persist using docker-compose

I keep losing my data when i restart my docker, here is my docker-compose.yml

postgres:
  image: postgres
  volumes:
    - /data/myproject/postgres:/var/lib/postgresql/data
  ports:
    - '15432:5432'
  environment:
    POSTGRES_PASSWORD: mypassword
    POSTGRES_USER: mypassword

Any help would be appreciated, thanks

Upvotes: 3

Views: 216

Answers (1)

VonC
VonC

Reputation: 1324228

Since you are using boot2docker, you need to know that only /Users is shared between the host (a Mac for instance) and the docker VM.

That means when you restart your VM, anything stored outside /Users (like /data/myproject/postgres) would be lost.

Try mounting a volume with a host path which is actually shared between your host and your VM.

Upvotes: 1

Related Questions