Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 955
Mr Mixin Avatar asked Feb 02 '26 12:02

Mr Mixin


1 Answers

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.

like image 174
VonC Avatar answered Feb 04 '26 02:02

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!