Bind mounts vs. Volumes in Docker Compose#
https://docs.docker.com/storage/bind-mounts/#choose-the–v-or—mount-flag
Using simple volume mounts creates a directory if the file does not exist, e.g.
docker run \
--rm -it \
--user $(id -u):$(id -g) \
-v /tmp/foo.cfg:/tmp/foo.cfg \
debian:bullseye true
stat /tmp/foo.cfg
rm /tmp/foo.cfg
Using the --mount
flag does not, e.g.:
docker run \
--rm -it \
--user $(id -u):$(id -g) \
--mount source=/tmp/foo.cfg,destination=/tmp/foo.cfg \
debian:bullseye true
# errors out, as it should be
https://docs.docker.com/compose/compose-file/compose-file-v3/#long-syntax-3
Limit Memory (RAM) and CPU in Docker Compose
Marking Environment Variables as Required in Docker Compose