Im running a simple docker-compose.yml
file containing the following directives:
services:
postgres:
image: postgres:12
volumes:
- db-data:/var/lib/postgresql/data:cached
volumes:
db-data:
Everything works as expected and PostgreSQL has no trouble creating and finding its database files it seems. However /var/lib/postgresql
does not even exist in the host filesystem. /var/lib/docker/volumes/
contains files, but where does /var/lib/postgresql/data
point to if not the host filesystem?
You can inspect
your volume
and get the exact location on the host filesystem. Below you can find a small example of how the command output looks like, check the value of Mountpoint
:
$ docker volume inspect volume_example_db-data
[
{
"CreatedAt": "2021-07-30T12:34:57+03:00",
"Driver": "local",
"Labels": {
"com.docker.compose.project": "volume_example",
"com.docker.compose.version": "1.27.4",
"com.docker.compose.volume": "db-data"
},
"Mountpoint": "/var/lib/docker/volumes/volume_example_db-data/_data",
"Name": "volume_example_db-data",
"Options": null,
"Scope": "local"
}
]
By default, the name of the volume gets the folder name as a prefix, in my case it was volume_example
but in your case it will be something similar:
/var/lib/docker/volumes/volume_example_db-data/_data
/var/lib/docker/volumes/ name of volume /_data
cd /var/lib/docker/volumes/volume_example_db-data/_data
# ls
base pg_commit_ts pg_hba.conf pg_logical pg_notify pg_serial pg_stat pg_subtrans pg_twophase pg_wal postgresql.auto.conf postmaster.opts
global pg_dynshmem pg_ident.conf pg_multixact pg_replslot pg_snapshots pg_stat_tmp pg_tblspc PG_VERSION pg_xact postgresql.conf postmaster.pid