Windows Docker mongo容器不适用于卷挂载 [英] Windows Docker mongo container doesn't work with volume mount

查看:411
本文介绍了Windows Docker mongo容器不适用于卷挂载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下docker命令

I have the following docker command

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

我从docker/mongo得到以下错误响应

and I get the following error response from 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时,我可以工作,但是我需要保留数据,所以我需要以某种方式挂载该卷,只是不确定此时我做错了什么.

now when I remove the volume mongo works but I need to persist my data so I need to mount the volume somehow, just not sure what i am doing wrong at this point.

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

I do see the files appearing in my folder but not sure why I get the 100 error

推荐答案

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

To get around this, you can employ a tool like rsync to move the db files into mapped directory while Mongo is running. The underlying bug has to do with latency between the Windows mapped volume and that bind path within the container. Offloading the work to rsync decouples the latency from Mongo's runtime requirements.

示例

像这样创建基本的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开始.

Then, when launching the container, just start with ./init.sh as your ENTRYPOINT.

这篇关于Windows Docker mongo容器不适用于卷挂载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆