A new named volume shows the image's files. A bind mount of an empty folder shows an empty folder.
New, empty named volume: when the container starts, Docker copies the existing contents of /app/config from the image into the volume. The container sees the image's files. From then on, those files live in the volume. Docker only copies when the volume is empty. You can turn this copying off with the volume-nocopy option.
Bind mount: Docker copies nothing. A bind mount puts a host folder over the path. It hides the image's files, so the container sees an empty folder.
This surprises people in both directions:
- A volume filled by an old image version keeps the old files after you ship a new image. Docker only copies into an empty volume, so the new files never arrive.
- A bind mount can silently remove config files that the app expects.
- Docker fills an empty named volume with the image's files at that path.
- This copy only happens when the volume is empty, and the volume-nocopy option turns it off.
- Bind mounts never copy, and they hide the image's files.
- Old volume contents stay in place when you upgrade the image.
Read more