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:
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": ""
}
],
Which makes it seem like the data is being stolen by another volume I didn't code myself. Not sure why that is. Is the postgres image creating that volume for me? If so, is there some way to use that volume instead of the volume I'm mounting when I restart? Otherwise, is there a good way of disabling that other volume and using my own, ./database
?
initdb
command line to initialize your database cluster? – Ariosefrom app import db
anddb.create_all()
from adocker run
after starting the containers. I don'tinitdb
directly from the command line. – Jackasssudo su -
and look in./database/data
. There's nothing in there as far as I can tell. – Jackass