环境准备

准备三台Linux机器,之间可以通过SSH相互通信。
hostname ip ssh username ssh password
docker-host1 192.168.200.10 vagrant vagrant
docker-host2 192.168.200.11 vagrant vagrant
docker-host3 192.168.200.12 vagrant vagrant

安装plugin

在其中两台机器上安装一个plugin vieux/sshfs
  1. docker plugin install --grant-all-permissions vieux/sshfs

创建volume

  1. docker volume create --driver vieux/sshfs \
  2. -o sshcmd=vagrant@192.168.200.12:/home/vagrant \
  3. -o password=vagrant \
  4. sshvolume
查看
  1. docker volume ls
  2. docker volume inspect sshvolume

创建容器挂载Volume

  1. docker run -it -v sshvolume:/app busybox sh
  2. ls
  3. cd /app
  4. ls
  5. echo "this is ssh volume"> test.txt
  6. ls
  7. more test.txt
这个文件我们可以在docker-host3上看到
  1. pwd
  2. ls
  3. more test.txt