Windows Docker mongo容器无法使用卷装载

时间:2017-03-19 22:19:38

标签: mongodb docker docker-compose mounted-volumes

我有以下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错误

1 个答案:

答案 0 :(得分:0)

要解决此问题,您可以使用rsync之类的工具在Mongo运行时将db文件移动到映射目录中。潜在的错误与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开始。