2

I use autofs to mount a remote folder via sshfs to my local machine. On the local machine I have a docker container running which uses the same mount as a volume.

If for whatever reason the mount is lost, the container is not able to see the volume, however as this is an autofs mount, the mount can be restored by simply accessing the appropriate folder, yet the container is not able to recover the volume, despite the mount being restored.

I would like to undertand whether there is a recommended method for determining if the mount point is restored and triggering the container to remount the volume accordingly?

I have considered using healthcheck to run a simple grep command against an expected file name in the volume, but this will only report whether the container is healthy or not, and not necessarily remount the volume.

The less elegant solution is to check whether the expected file is available through a docker exec command, try to remount the folder and restart the container. But this seems very much like a hammer approach to what is a simple problem.

Thanks a stack.

Ian B
  • 61
  • 1
  • 3

2 Answers2

0

After some further investigation on Askubuntu, I found some additional options for sshfs which keeps the connection alive. This seemed to do the trick, combined with a script which checks the mount directly and via a container shell and then restarts them if there is a failure.

autofs / sshfs additional options to include:

-o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3

I hope this helps.

Ian B
  • 61
  • 1
  • 3
0

You will have to mount with shared bind propagation. By default it's set to rprivate, which does not allow the container to propagate its replica mount to the host and vice versa.

Just replace the simple mount syntax in your compose file with the following snippet:

volumes:
  - type: bind
    source: /path/on/the/host
    target: /path/in/the/container
    bind:
      propagation: rshared
Dominik
  • 101