Normally I would just give the abs path of the folder in the volume section in the container, but now I’m trying to learn how to make named volumes as my docker compose file needs to share the same volumes sometimes.
My question is: can we create a named volume that bind mount to a folder that has not exist yet?
Named volumes and bind mounts are different things
Bind mount will mount a volume from the host machine’s defined path
A named volume will create a volume managed by docker. It is not bound into a host path and will not just create a folder out of thin air - there is no path defined for that, the named volumes are stored where Docker Daemon stores its files
Both mount types can be used by multiple containers
Note: bind propagation on named volumes backed by a bind can not be configured the same way, like it can be configured for binds. If you have no idea what bind propagation is, then it’s most likely irrelevant for you.
Update: I forget to address @tamashika’s question: the path used in device: must exist in order for the volume to work.