Share data among machines using Docker Volume - saviovettoor/DevOps-wiki GitHub Wiki

  1. Install the vieux/sshfs plugin on all nodes in the swarm.
]#docker plugin install --grant-all-permissions vieux/sshfs
  1. Set up an additional server to use for storage. You can use the Ubuntu 18.04 Bionic Beaver LTS image with a size of Small. On this new storage server, create a directory with a file that can be used for testing.
mkdir /home/user/external
echo External storage! > /homeuser/external/message.txt
  1. On the swarm manager, manually create a Docker volume that uses the external storage server for storage. Be sure to replace the text <STORAGE_SERVER_PRIVATE_IP> and with actual values.
 docker volume create --driver vieux/sshfs \
   -o sshcmd=user@<STORAGE_SERVER_PRIVATE_IP>:/home/user/external \
   -o password=<PASSWORD> \
   sshvolume
 docker volume ls
  1. Create a service that automatically manages the shared volume, creating the volume on swarm nodes as needed. Be sure to replace the text <STORAGE_SERVER_PRIVATE_IP> and with actual values.
 docker service create \
   --replicas=3 \
   --name MyStorageService \
   --mount volume-driver=vieux/sshfs,source=cluster-volume,destination=/app,volume-opt=sshcmd=user@<STORAGE_SERVER_PRIVATE_IP>:/home/user/external,volume-opt=password=<PASSWORD> busybox cat /app/message.txt
  1. Check the service logs to verify that the service is reading the test data from the external storage server.
]# docker service logs MyStorageService

MORE: link

⚠️ **GitHub.com Fallback** ⚠️