Cloud and Container Basics
In Docker, which of the following correctly describes named volumes and bind mounts, used to keep data written by a container?
- AA volume is stored in an area managed by Docker and a bind mount in a host directory you specify, and both remain after the container is removed
- BData in a named volume remains after the container is removed, but data in a bind mount also disappears from the host directory when the container is removed
- CBoth are created as part of the container's writable layer, so removing the container with docker rm also deletes the data
Show answer and explanation
Answer: A. A volume is stored in an area managed by Docker and a bind mount in a host directory you specify, and both remain after the container is removed
Data written to a container's writable layer disappears when the container is removed, so data that must be kept is placed outside the container. A named volume is created in an area managed by Docker and remains until it is explicitly deleted, for example with docker volume rm. A bind mount makes any host directory visible inside the container, and the data simply remains as files on the host. Bind mounts are common during development, when source code edited on the host should take effect immediately, and volumes are common for data whose management is best left to Docker, such as database data.
- A. Correct. The locations differ, but both are outside the container, so the data remains.
- B. The data of a bind mount is the files in the host directory themselves, so removing the container does not delete them.
- C. Both are outside the container's writable layer, so they remain after the container is removed.