Problem Description
My docker compose file has three containers, web, nginx, and postgres. Postgres looks like this:
postgres:
container_name: postgres
restart: always
image: postgres:latest
volumes:
- ./database:/var/lib/postgresql
ports:
- 5432:5432
My goal is to mount a volume which corresponds to a local folder called `./database` inside the postgres container as `/var/lib/postgres`. When I start these containers and insert data into postgres, I verify that `/var/lib/postgres/data/base/` is full of the data I'm adding (in the postgres container), but in my local system, `./database` only gets a `data` folder in it, i.e. `./database/data` is created, but it's empty. Why?
Notes:
- [This suggests my above file should work.](https://github.com/docker/compose/issues/2971)
- [This person is using docker services which is interesting](https://stackoverflow.com/questions/39175194/docker-compose-persistent-data-mysql)
### UPDATE 1
Per Nick's suggestion, I did a `docker inspect` and found:
"Mounts": [
{
"Source": "/Users/alex/Documents/MyApp/database",
"Destination": "/var/lib/postgresql",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
},
{
"Name": "e5bf22471215db058127109053e72e0a423d97b05a2afb4824b411322efd2c35",
"Source": "/var/lib/docker/volumes/e5bf22471215db058127109053e72e0a423d97b05a2afb4824b411322efd2c35/_data",
"Destination": "/var/lib/postgresql/data",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""...
AI-Generated Solution
Powered by LMSouq AI · GPT-4.1-mini
Analyzing problem and generating solution…
Was this solution helpful?