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

1 Answer 1

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.

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

5 Comments

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/<vm-username>/ ?
@MrMixin No: your host machine would be a Mac or a Windows if you need a boot2docker VM.
@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.
So on a MAC system with boot2docker would he put his path as /Users/data/myproject/postgress instead of /data/myproject/postgres
@DrManhattan Yes, that is the idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.