Automation, Orchestration, and Scripting
A Compose file defines a db service running PostgreSQL. After each docker compose down followed by docker compose up -d, the database is empty. The administrator wants the data kept in a Docker-managed volume that survives down. Which change to the Compose file achieves this?
Show the answer
Correct answerA. Mount a named volume at /var/lib/postgresql/data and declare it under the top-level volumes key
A named volume mapped to the data directory and declared in the top-level volumes section lives outside the container, so down does not delete it. A restart policy only restarts containers and does not preserve data, and tmpfs is memory-backed and lost at stop.