Docker: Use --mount instead of -v for mounting docker paths


Recommended Posts

Currently, I believe that unraid is using -v to mount paths in docker. This has the undesirable side effect of creating the path in the host system if it doesn't exist. So, for example, if you've use a bind mount in docker pointing to /mnt/disks/data and /mnt/disks/data does not exist, it will be created in the host system as an empty directory, leading to problems when you want to actually mount something into /mnt/disks/data.

 

Using the --mount syntax instead will not auto create paths. See https://docs.docker.com/storage/bind-mounts/ for reference.

 

Quote

Differences between -v and --mount behavior

Because the -v and --volume flags have been a part of Docker for a long time, their behavior cannot be changed. This means that there is one behavior that is different between -v and --mount.

If you use -v or --volume to bind-mount a file or directory that does not yet exist on the Docker host, -v creates the endpoint for you. It is always created as a directory.

If you use --mount to bind-mount a file or directory that does not yet exist on the Docker host, Docker does not automatically create it for you, but generates an error.

 

  • Upvote 1
Link to comment
21 minutes ago, Squid said:

Damned if you do, damned if you don't.

 

Many required folders may need to be created depending upon the container - most notably, the appdata folder.

 

I think unraid creating the folders when you add a new container is ok, but I don't see the use case for docker ever creating folders when you start a container (its gonna create an empty folder because the appdata folder is not mounted)

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.