Question: How to expose the mounted folder at MacOS/Windows

Hello community,

I’m looking for the best way to expose a mounted folder from a container back to the main host machine (macOS or Windows).

A critical limitation is that I cannot install FUSE on the host machine.

My simplified example uses the following volume flag:

docker run --rm -it \
  --privileged \
  --user root \
  -v ./local:/mnt/minimal_folder:rshared \
  alpine:latest sh -c "
    mount -t ramfs ramfs /mnt/minimal_folder &&
    echo 'ramfs mounted successfully' &&
    df -h /mnt/minimal_folder &&
    echo 'Testing write...' &&
    echo 'Hello World' > /mnt/minimal_folder/test.txt &&
    cat /mnt/minimal_folder/test.txt && sleep 300
  "

This seems like a common requirement, and I’m curious how others approach it. Specifically, how can I achieve this without using the rshared option?

My initial ideas are:

  1. Two-Volume Setup: Mount the first volume, mount the second volume for exposure, and use bi-directional synchronization.
  2. Network Share: Expose the folder via Samba or NFS.

Are there any other existing or preferred methods for implementing this?

Thank you in advance for your insights!

https://docs.docker.com/engine/storage/bind-mounts/#configure-bind-propagation

Quote:

Note

Mount propagation doesn’t work with Docker Desktop.

I wrote about ways in a blog post

https://dev.to/rimelek/everything-about-docker-volumes-1ib0#docker-desktop-volumes

I also mentioned NFS. I don1t think there is a better way. You can check what you can see on Windows through the shared WSL filesystem from the file explorer.

Even if you use NFS, you would need to add that into the same container. Since you are mounting ramfs, I guess you could try shm instead

https://docs.docker.com/reference/compose-file/services/#shm_size

Using it together with ipc

https://docs.docker.com/reference/compose-file/services/#ipc

You could run one container generating the data into memory and use another to for the NFS server. I never tried sharing a shared memory through NFS, so that is just an idea. I’m not sure if it works.