1

With Ubuntu, USB drives are automatically mounted at /media/<user>/<drive> when they are plugged in. I wanted to use this to make newly connected USB drives available in a running Docker container. So I used -v /media/<user>:/media/<user> to mount the whole parent directory of the USB mount points to the container.

This works well if the USB drive was connected before the container starts. In this case the USB mount point has permissions 0777 and belongs to <user>. If a USB drive is connected when the container is already running, the mount point appears in the container but has permissions 0700 and is owned by root instead!

Can anyone shed some light on what is possibly happening here? I can imagine that the USB drives are automatically mounted as 0700 belonging to root by default and afterwards some other mechanism kicks in to change this to 0777 and <user>. Only the change is not picked up by Docker. Is this true?

I already digged through tons of forum threads and mailing lists but couldn't figure out the mechanism. I also tried some udev rules (like this one) but these had no effect.

3

I know the question is from 2018, but a solution would be using bind-mounts and setting the "bind propagation" to "shared" (not available for volumes).

Instead of:

-v /media/<user>:/media/<user>

Use:

--mount type=bind,source=/media/<user>,target=/media/<user>,bind-propagation=shared

More info about bind-propagation: https://docs.docker.com/storage/bind-mounts/#configure-bind-propagation

1
  • This is exactly what I was looking for, thanks! In my case rslave seems to be perfect. – Mouagip Jan 6 '20 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.