假设我有一个mongod实例,该实例需要从远程主机上的目录读取/写入数据。有没有办法:
就我而言,假设需要挂载的远程目录是/data/db
。我目前对第二个选项的处理方法如下:
/local/data/db
sshfs
将远程目录挂载到本地:sudo sshfs -o allow_other,defer_permissions,IdentityFile=/Users/<your_username>/.ssh/id_rsa <your_username>@<host_name>:/data/db /local/data/db
docker run -p 27017:27017 -v /local/data/db:/data/db --name mongo mongo
显然失败了,但出现以下错误:
chown: changing ownership of '/data/db/._admin.ns': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-19T08-42-17Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-19T07-58-39Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-31T04-00-13Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-02-15T15-52-17Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-19T07-13-47Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-04-06T23-03-58Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-19T08-34-46Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-02-17T23-37-17Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-21T18-30-13Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-04-02T12-20-13Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-02-24T19-57-21Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-11-03T13-34-09Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-11-05T21-24-09Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-04-04T18-21-07Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-18T10-49-27Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-10-29T22-24-37Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-19T08-24-02Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-02-13T08-32-17Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.interim': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-02-20T06-07-19Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-19T07-02-42Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-11-01T05-49-37Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-19T04-01-35Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-02-29T10-42-21Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-19T07-26-52Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-28T19-20-13Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-02-27T03-12-21Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-26T10-40-13Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-19T08-40-20Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-19T09-33-10Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-24T03-15-13Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-02-22T12-07-20Z-00000': Operation not permitted
chown: changing ownership of '/data/db/diagnostic.data/._metrics.2020-03-18T09-27-49Z-00000': Operation not permitted
chown: changing ownership of '/data/db/journal/._lsn': Operation not permitted
chown: changing ownership of '/data/db/journal/._j._2': Operation not permitted
chown: changing ownership of '/data/db/journal/._j._1': Operation not permitted
chown: changing ownership of '/data/db/journal/._prealloc.2': Operation not permitted
chown: changing ownership of '/data/db/._.': Operation not permitted
chown: changing ownership of '/data/db/._config.0': Operation not permitted
chown: changing ownership of '/data/db/._local.0': Operation not permitted
chown: changing ownership of '/data/db/._diagnostic.data': Operation not permitted
chown: changing ownership of '/data/db/._journal': Operation not permitted
chown: changing ownership of '/data/db/_tmp/._1586251487696721': Operation not permitted
chown: changing ownership of '/data/db/._config.ns': Operation not permitted
chown: changing ownership of '/data/db/._storage.bson': Operation not permitted
chown: changing ownership of '/data/db/._mongod.lock': Operation not permitted
chown: changing ownership of '/data/db/.__tmp': Operation not permitted
chown: changing ownership of '/data/db/._local.ns': Operation not permitted
chown: changing ownership of '/data/db/._admin.0': Operation not permitted
chown: changing ownership of '/data/db/._local.1': Operation not permitted
答案 0 :(得分:0)
您可以通过使用sshfs
volume driver将卷安装到使用远程计算机上的数据的mongodb容器中。 Here,您可以找到docker官方文档及其示例。
要使用ssh密钥,您需要安装sshfs
插件,例如:
docker plugin install vieux/sshfs sshkey.source=/Users/<your_username>/.ssh/
您需要验证与数据托管计算机的SSH连接可用。如果是这样,您可以创建如下卷:
docker volume create \
-d vieux/sshfs \
-o sshcmd=<user>@<host>/data/db \
-o IdentityFile=/Users/<your_username>/.ssh/id_rsa
mongodata
然后,您将可以像这样挂载该卷:
docker run -d \
-p 27017:27017 \
-v mongodata:/data/db \
--name mongo \
mongo
如果再次遇到错误,我强烈建议您弄清楚密钥的用法。您可以找到更多信息here。