Reputation: 266960
I am trying to get docker volumes working.
I have defined a volume in my Dockerfile as follows:
version: "3"
services:
redis:
image: redis:alpine
ports:
- "6379:6379"
db:
image: postgres:9.4
#container_name: db
volumes:
- "db-data:/var/lib/postgresql/data"
volumes:
db-data:
Now my question is, when I do a docker-compose up I don't see my data persisted on my local laptop (or server).
I just want to test/verify that my data is saving to the host's filesystem, so if I start/stop docker when it restarts it reads from the database file on the host.
Upvotes: 0
Views: 67
Reputation: 158758
That construct saves data in a named volume; if you look under /var/lib/docker/volumes
as root you should be able to see it there (though mucking around in /var/lib/docker
generally isn't advisable; and I believe this is one of the things where Docker Compose will change the name to try to make it unique).
If you want the data to be saved in a host directory, change the volume declaration to explicitly have a relative or absolute path. You won't need the explicit volume declaration, and for this you can remove the volumes block entirely. That would leave you with a docker-compose.yml
that looks like:
version: "3"
services:
db:
image: postgres:9.4
volumes:
- "./db-data:/var/lib/postgresql/data"
Upvotes: 1