It's quite straightforward how to share a volume between containers when they share the FS, however it gets more complicated when one endpoint targets a directory that not only has a different FS but also this FS changes after the container runs, and the other one wants to replicate it (ro mode).
An important part is that the shared volume should not be stored on the host machine. It should only "live" between the containers and not be persistent.
The snippet below won't work, it's just to give an idea on what I am trying to achieve (see comments).
version: '3.7'
services:
# This service spins up with /mnt being an empty, unmounted dir.
# It then runs an executable that will mount a FUSE filesystem
# under /mnt
app:
# application
volumes:
- type: bind
source: shared_mnt
target: /mnt
bind:
propagation: shared
privileged: true
devices:
- '/dev/fuse'
# This service wants to read (read-only) the contents of this
# FUSE fs from `app` service, thus it should act as a slave
nginx:
# nginx
volumes:
- type: bind
source: shared_mnt
target: /whateve # a read-only replica of `app`'s /mnt dir (does not have to be a fuse FS)
bind:
propagation: shared
volumes:
shared_mnt: