How exactly am I supposed to manage volumes with podman / docker? #28398
-
|
SO I have the following minimal compose file for a postgres instance with pgadmin for admin stuff: services:
main_postgres:
image: pgrouting/pgrouting:17-3.5-main
restart: always
shm_size: 128mb
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: admin
main_pgadmin:
image: dpage/pgadmin4:9
restart: always
shm_size: 256mb
ports:
- "8180:80"
environment:
PGADMIN_DEFAULT_EMAIL: admin@admin.com
PGADMIN_DEFAULT_PASSWORD: admin
depends_on:
- main_postgresI added a "volume" section to the The data loss isn't that concerning because I already have exports I can restore from but I need clarification on a few things so that this doesn't happen again:
// obviously they'd have to be referenced in their respective sections too
volumes:
postgres_data
pgadmin_data
I'm normally not the devops guy, I'm just a regular dev that has to use docker sometimes, any help with this is much appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Great questions - let me go through each one.
You might be able to recover your data from there if the hash-named volume is still listed.
Absolutely - named volumes are the standard recommendation for exactly this reason. Your compose snippet is almost right, just missing the colons: And reference them in each service: Named volumes survive podman compose down, are easy to inspect by name, and won't get accidentally orphaned.
podman cp - simplest for one-off copies: podman cp myfile.csv main_postgres:/tmp/ Then you can drop files into that folder from Explorer and access them inside the container at /tmp/imports. Use named volumes only for persistent state (database files, pgadmin config), and bind mounts for input data you manage yourself. |
Beta Was this translation helpful? Give feedback.
Great questions - let me go through each one.
Do Podman/Docker create volumes automatically if none are specified?Yes, but only if the image declares a VOLUME instruction in its Dockerfile. Both postgres and pgadmin4 do this - so out of the box, they get anonymous volumes (random hashes like a3f9b2c1...). These persist across podman compose down restarts, but are easy to accidentally orphan.
Did adding the volumes: section cause data loss?Most likely yes, but not because containers "rebuilt" - the image layers stay the same. What probably happened is that your new bind mount shadowed the anonymous volume that was previously holding your data. When Podman saw a new mount point for /var…