3

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

Mr Mixin
  • 893
  • 3
  • 10
  • 15

1 Answers1

1

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thanks for the response, so you mean if m host machine is an ubuntu vm i need to map it to any dir in /home// ? – Mr Mixin Nov 19 '15 at 16:13
  • @MrMixin No: your host machine would be a Mac or a Windows if you need a boot2docker VM. – VonC Nov 19 '15 at 16:14
  • @MrMixin If your host was Ubuntu, you wouldn't need a boot2docker VM. Even if your host is using an Ubuntu VM, you wouldn't need boot2docker since you would do docker directly within the Ubuntu VM. – VonC Nov 19 '15 at 16:15
  • So on a MAC system with boot2docker would he put his path as `/Users/data/myproject/postgress` instead of `/data/myproject/postgres` – Dr Manhattan Feb 01 '16 at 17:58
  • @DrManhattan Yes, that is the idea. – VonC Feb 01 '16 at 19:15