Docker swarm and remote filesystems, an ssh fs example
Scenario: we have a swarm of 3 servers and a 4th server which will be our storage, a directory on this host that will be mounted over ssh
Scenario: we have a swarm of 3 servers and a 4th server which will be our storage, a directory on this host that will be mounted over ssh
Solution:
Install the following plugin on all servers of the swarm$ docker plugin install --grant-all-permissions vieux/sshfs
latest: Pulling from vieux/sshfs
52d435ada6a4: Download complete
Digest: sha256:1d3c3e42c12138da5ef7873b97f7f32cf99fb6edde75fa4f0bcf9ed277855811
Status: Downloaded newer image for vieux/sshfs:latest
Installed plugin vieux/sshfs
On the storage server create the following directory and file
Note: kpatronas is my home directory, adjust this to your environment
$ mkdir /home/kpatronas/data
$ echo Hello world! > /home/kpatronas/data/message.txtNow on the swarm manager lets create the ssh volume
IP_ADDRESS: is the ip address of the ssh storage
PASSWORD: the ssh password used to connect
sshvolume: the name of the volume$ docker volume create --driver vieux/sshfs -o sshcmd=kpatronas@<IP_ADDRESS>:/home/kpatronas/data -o password=<PASSWORD> sshvolume
Use docker volume ls to verify the creation$ docker volume ls
DRIVER VOLUME NAME
local my-volume
vieux/sshfs:latest sshvolume
local test
Lets create a service that will use the new volumedocker service create --replicas=3 --name storage-service --mount volume-driver=vieux/sshfs,source=sshvolume,destination=/app,volume-opt=sshcmd=kpatronas@<IP_ADDRESS>:/home/kpatronas/data,volume-opt=password=<PASSWORD> busybox cat /app/message.txt
Check logs with docker service logs to verify that it worksdocker service logs storage-service