Windows Docker mongo 容器不适用于卷装载

Windows Docker mongo container doesn't work with volume mount

我有以下 docker 命令

docker run -v //c/data:/data/db mongo

我从 docker / mongo

得到以下错误响应
MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=8706cbf1b78f
db version v3.4.2
git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
OpenSSL version: OpenSSL 1.0.1t  3 May 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: debian81
    distarch: x86_64
    target_arch: x86_64
options: {}
wiredtiger_open config: create,cache_size=478M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
WiredTiger error (1) [1489982988:687653][1:0x7fec9df0ccc0], connection: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
Assertion: 28595:1: Operation not permitted src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 267
exception in initAndListen: 28595 1: Operation not permitted, terminating
shutdown: going to close listening sockets...
removing socket file: /tmp/mongodb-27017.sock
shutdown: going to flush diaglog...
now exiting
shutting down with code:100

现在当我删除卷时 mongo 可以工作但是我需要保留我的数据所以我需要以某种方式安装卷,只是不确定我现在做错了什么。

我确实看到文件出现在我的文件夹中,但不确定为什么会出现 100 错误

为了解决这个问题,您可以使用 rsync 之类的工具将 db 文件移动到映射目录中,而 Mongo 是 运行。潜在的错误与 Windows 映射卷和容器内的绑定路径之间的延迟有关。将工作卸载到 rsync 将延迟与 Mongo 的运行时要求分离。

例子

像这样创建一个基本的Dockerfile

FROM mongo:latest

RUN apt-get update && \ 
    apt-get install -y \
        rsync

ADD init.sh /init.sh

其中 init.sh 是:

#!/bin/bash

migrate_db() {
  while true
  do
    rsync -avh /data/db/* /data/mapped-db
    sleep 5
  done
}

migrate_db &

#Execute a command
mongod --smallfiles --logpath=/dev/null --verbose &

#Wait
wait $!

然后,启动容器时,只需以 ./init.sh 作为您的 ENTRYPOINT 开始。