I am beginner docker user.
I installed docker and postgresql in Mac OS.
and why most of documents mention the directory
/var/lib/postgresql/data as an volume setting???
Because in my local directory, there is not existed /var/lib/postgresql..
Is it default option? or am I missing something?
2
Answers
If you are using official PostgreSQL image from Docker Hub, then you can check the contents of its
Dockerfile
. E.g. here is a fragment of postgres:15 image responsible for data directory:As you can see Postgres is configured to have data in that directory. And to persist the data even if container is stopped and removed, the volume is created. Volumes have lifetime independent of the container which allows them to "survive".
Yes, correct,
/var/lib/postgresql
does not exist on your local computer, but it does in the created container. The volumes parameter is used to associate the local data with the container data, in order to preserve the data in case the container crashesFor example:
Above we link the local directory from the left side to the container directory