首页 > 解决方案 > Docker 使用 sshfs 挂载远程卷

问题描述

我知道这个问题已经在网上完成,但我无法找到适合我的解决方案。

我安装了一台服务器 (VM1),sshfs它应该提供远程文件系统存储。我有另一台运行容器的服务器 (VM2),我希望这些容器使用 VM1 中托管的卷。

我遵循了这个官方的 docker guide 所以在 VM1 我跑了:

docker plugin install vieux/sshfs DEBUG=1 sshkey.source=/home/debian/.ssh/

在 VM 2 中,我运行:

docker volume create --name remotevolume -d vieux/sshfs -o sshcmd=debian@vm1:/home/debian/sshfs300 -o IdentityFile=/home/csicari/data/Mega/lavoro/keys/vm-csicari.key -o -o allow_other  -o nonempty

这是检查输出:

[
  {
   "CreatedAt": "0001-01-01T00:00:00Z",
   "Driver": "vieux/sshfs:latest",
   "Labels": {},
   "Mountpoint": "/mnt/volumes/895d7f7679f69131500c786d7fe5fdc1",
   "Name": "remotevolume",
   "Options": {
             "IdentityFile": "/home/csicari/data/Mega/lavoro/keys/vm-csicari.key",
             "sshcmd": "debian@vm1:/home/debian/sshfs300"
  },
  "Scope": "local"
  }
]

在 VM1 中,我还运行了:

docker run -it -v remotevolume:/home -d ubuntu

但我得到了这个错误:

docker: Error response from daemon: VolumeDriver.Mount: sshfs command execute failed: exit status 1 (read: Connection reset by peer
). See 'docker run --help'.

标签: dockersshfs

解决方案


也许这是一个很长的问题,也许它会帮助其他新手。远程 VM/etc/ssh/sshd_config文件内容检查属性PasswordAuthentication yes 如果它是“是”,我们可以使用密码传递参数。否则,将其更改为“否”并重新启动 ssh 或 sshd 服务。

service ssh restart
service ssh status

还有密码验证。根据您的 PAM 配置,请同时检查。

如果是AWS实例使用命令passwdubuntu重置密码#这里ubuntu是ec2 ubuntu实例中的默认用户


推荐阅读