4

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:
fcdt
  • 2,371
  • 5
  • 14
  • 26
Mike
  • 842
  • 1
  • 9
  • 31
  • 1
    Not persisting the data to disk and sharing the volume isn't possible using a [`tmpfs`](https://docs.docker.com/storage/tmpfs/). Using a `bind-mount` volume will persist the files to disk. You could back the volume with an NFS share i.e. [EFS](https://stackoverflow.com/a/57742017/1423507) but then the data will be persisted to the NFS servers disk. You can look through the existing `volume plugins` if anything fits your requirements but I'm not aware anything that you can `docker volume create` with that would store the data in memory and which can be shared between containers. – masseyb Oct 03 '20 at 20:20
  • 2
    Could probably run an [`nfs-server-alpine`](https://hub.docker.com/r/itsthenetwork/nfs-server-alpine) NFS server in `docker` backed by a `tmpfs` volume then configure your services to output their volumes to that NFS server instance. – masseyb Oct 03 '20 at 21:36
  • 1
    This sounds like a nice workaround. Thanks for the suggestion @masseyb – Mike Oct 05 '20 at 18:14

0 Answers0