‹ All Docker Interview Questions questions

Docker Interview Question 5: Volume Bind tmpfs Choice

Docker Interview Questions · Test 1 · question 5 of 10

Storagemedium

An image ships seed files in /app/data, and the application writes its state there at runtime. You need three things: the data survives docker rm and re-creating the container; storage is managed by Docker rather than tied to a directory layout on the host; and on the very first run the seed files from the image are present in /app/data. Which mount should you use?

Select one answer
Show answer and explanation

Answer:

  • C. A named volume, -v appdata:/app/data, that does not exist yet when the container first starts

Volumes are created and managed by Docker and persist after the container is removed. When you mount an empty volume into a container directory that already contains files, those files are copied into the volume by default, and a volume that does not exist yet is created empty. So the first run pre-populates appdata with the image's seed files, and later containers reuse the same data.

Option A persists data, but it depends on a host path, which the stem rules out. It also fails the seed requirement: a bind mount over a directory obscures the files that were already there, so the image's seed files would be hidden behind the empty host directory.

Option B is not persistent. A tmpfs mount lives in host memory and is removed when the container stops, so nothing survives.

Option D keeps state in the container's writable layer, which is deleted with the container, and docker commit turns runtime state into image layers, not a data-persistence mechanism.

References: Volumes; tmpfs mounts

Practice Test 1 ›

Study guides for Docker Interview Questions