sshfs

13/07/2020

ATTENTION : never create two mounts to the same place with docker volumes.
https://github.com/vieux/docker-volume-sshfs/issues/81
https://github.com/fentas/docker-volume-davfs/issues/6

standalone mode

install

apt-get install sshfs

put this in root crontab

crontab -e
@reboot /root/mountsshfs.sh

create script

emacs /root/mountsshfs.sh
sleep 10
mkdir /mnt/droplet
sshfs -o allow_other,default_permissions,IdentityFile=~/.ssh/id_rsa root@localhost:/ /mnt/droplet

remove mount

umount /mnt/droplet

sshfs docker plugin

docker plugin install vieux/sshfs
docker plugin disable vieux/sshfs
docker plugin set vieux/sshfs sshkey.source=/root/.ssh/
docker plugin enable vieux/sshfs
docker inspect vieux/sshfs

test that it works

docker volume create -d vieux/sshfs --name sshvolume -o sshcmd=root@flatbay.fr:/root/docker/flatbay/uploads -o IdentityFile=/root/.ssh/id_rsa
docker run --rm -it -v sshvolume:/testfolder busybox ls /testfolder

equivalent docker compose

version: "3.3"

# docker exec -ti test ls /mount

services:
    test:
        image: busybox
        restart: always
        container_name: test
        volumes:
            - sshflatbaytest:/mount
        command: sleep 10000

volumes:
    sshflatbaytest:
        # name: sshflatbay
        # external: true
        driver: vieux/sshfs:latest
        driver_opts:
            sshcmd: "root@flatbay.fr:/root/test"
            IdentityFile: "/root/.ssh/id_rsa"
            # allow_other: ""
            # default_permissions: ""

erreur volume nonempty

Error response from daemon: error while mounting volume '/mnt/volumes/53c491c3a851fe9a96e85598643e6423': VolumeDriver.Mount: sshfs command execute failed: exit status 1 (fuse: mountpoint is not empty
fuse: if you are sure this is safe, use the 'nonempty' mount option

n gros le dossier sur lequel doit se monter le dossier ssh distant est déjà rempli avec des fichiers.

On peut vérifier les volumes existants ici :

docker volume ls

Ils sont montés ici :

ls -la /var/lib/docker/plugins/c1161890d553c780089f6fc2cab7663d7dacf2deaf6c7bd82e5486ba4b0482e3/propagated-mount

il suffit de supprimer le conteneur docker(docker rm), puis le volume (docker volume rm) puis le redemarrer.