Why mount a volume for a PostgreSQL container?
Options
- To speed up the queries that the database handles in memory
- Container data is lost when the container is removed; a volume keeps it (Correct option)
- Volumes are needed so that the container can expose its ports
- To share the kernel of the host with the database process
Answer
Data in the container's writable layer is lost when the container is removed; a volume persists it
Why
Containers are meant to be disposable: you delete and recreate them on every update. Anything written inside the container is deleted with it.
A volume is storage managed outside the container's lifecycle. Mounting it at the database's data folder keeps the data when the container is replaced.
Remember
Data that must survive → volume.