Share volume between compose containers, with one of them providing its filesystem?

1.3k views Asked by At

I'm trying to setup some dockerised NAS, with mergerfs and samba:

services:

  mergerfs:
    build: ./mergerfs  # just debian and install latest release
    cap_add:
      - SYS_ADMIN
    devices:
      - /dev/fuse:/dev/fuse
    volumes:
      - media:/mnt/pool
      - /mnt/data0:/mnt/data0
      ...
   ...

  samba:
    image: dperson/samba
    command: -s'media;/srv/media;yes;no;yes'  # guest allowed, not RO
    volumes:
      - media:/srv/media
    depends_on:
      - mergerfs
    ...

volumes:
  media:

The problem is that, while I can read/write to /srv/media on samba, it doesn't get through to /mnt/pool on mergerfs.

(I can see this by watching docker-compose logs mergerfs while doing docker-compose exec samba sh -c "echo 'foobar' > /srv/media/test.txt" which shows nothing in logs, versus the equivalent exec mergerfs which does.)

How can I make this named volume media be a mere 'proxy' for the actual filesystem provided by the mergerfs service?

1

There are 1 answers

0
OJFord On BEST ANSWER

The answer lies in bind propagation.

In particular, here mergerfs needs media to be a type:bind rather than type:volume, so that it can be set to have (recursively) (r)shared bind propagation - which means that mounts configured by the container will be propagated back to the host.

That is, media:/mnt/pool becomes /mnt/media:/mnt/pool:rshared.