All jobs / DevOps / SRE / cloud / Containers
DevOps / SRE / cloud interview question · 0–1 years
In the team’s Docker Compose stack, Postgres loses all its data every time the container is recreated.
Why, and what is the fix?
The strongest answer
The data lives in the container’s writable layer, which goes away with the container; declare a named volume (or bind mount) on the data directory in the compose file so it outlives recreation
Why it works
Right — containers are disposable, volumes are where state lives. And remember `down -v` deletes named volumes too.
What a good answer covers
- Container layer is disposable.
- State goes in a volume.
- Declare it in compose.
- down -v removes volumes.
Answers that fall short
- Close, but not the strongest: Add `restart: always` so the container is not recreated as often
Restart policy changes when it restarts, not what happens to the layer when it is recreated. - Weak: Commit the running container to a new image after every change so the data is baked in
Committing containers turns data into images: huge, unversionable and wrong the moment two people do it. - Red flag: Run Postgres directly on the host and point the app at it; containers are not for databases
Giving up on containers because state was put in the wrong place skips the actual concept the interviewer is testing.
Who gets asked this
More Containers questions
- CI rebuilds a 12-minute Docker image on every commit. What do you change first?
- A production image is 1.8 GB and includes a compiler. What do you do?
- The app container connects to `localhost:5432` and gets connection refused, though the database container is…
- The Dockerfile has no USER line, so the app runs as root. Does that matter inside a container?
- The container registry has grown to terabytes, pulls from the cluster are slow, and a public registry started…
- What is the difference between an image and a container?
- A Dockerfile says `FROM node:latest`. What is wrong?
- A container can take all the memory on the node. What do you set?