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



我有以下 docker 命令

docker run -v //c/data:/data/db 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这样的工具在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.

最新更新