How do I configure mongo to run in docker to using

2019-05-23 17:20发布

问题:

I am trying to setup a docker image that will run a mongo instance which points to a drive location that isn't within the default docker container.

I used the following commands to create the issue:

docker run -p 27017:27017 --name mongo_test -v //c/Users/usrname/mongo_test:/data/db -d mongo

the container instantly fails, when I run the docker container logs mongo_test command I get back the following dump:

2017-03-13T04:33:33.358+0000 I CONTROL  [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=4f14ca0711c7
2017-03-13T04:33:33.358+0000 I CONTROL  [initandlisten] db version v3.4.2
2017-03-13T04:33:33.358+0000 I CONTROL  [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2017-03-13T04:33:33.358+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1t  3 May 2016
2017-03-13T04:33:33.358+0000 I CONTROL  [initandlisten] allocator: tcmalloc
2017-03-13T04:33:33.358+0000 I CONTROL  [initandlisten] modules: none
2017-03-13T04:33:33.358+0000 I CONTROL  [initandlisten] build environment:
2017-03-13T04:33:33.358+0000 I CONTROL  [initandlisten]     distmod: debian81
2017-03-13T04:33:33.358+0000 I CONTROL  [initandlisten]     distarch: x86_64
2017-03-13T04:33:33.358+0000 I CONTROL  [initandlisten]     target_arch: x86_64
2017-03-13T04:33:33.358+0000 I CONTROL  [initandlisten] options: {}
2017-03-13T04:33:33.363+0000 I STORAGE  [initandlisten] 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),
2017-03-13T04:33:33.384+0000 E STORAGE  [initandlisten] WiredTiger error (17) [1489379613:384669][1:0x7f1e6c4f5cc0], connection: /data/db/WiredTiger.wt: handle-open: open: File exists
2017-03-13T04:33:33.385+0000 I STORAGE  [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.1
2017-03-13T04:33:33.386+0000 E STORAGE  [initandlisten] WiredTiger error (1) [1489379613:386165][1:0x7f1e6c4f5cc0], connection: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
2017-03-13T04:33:33.386+0000 I -        [initandlisten] Assertion: 28595:1: Operation not permitted src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 267
2017-03-13T04:33:33.387+0000 I STORAGE  [initandlisten] exception in initAndListen: 28595 1: Operation not permitted, terminating
2017-03-13T04:33:33.387+0000 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2017-03-13T04:33:33.387+0000 I NETWORK  [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2017-03-13T04:33:33.387+0000 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2017-03-13T04:33:33.387+0000 I CONTROL  [initandlisten] now exiting
2017-03-13T04:33:33.387+0000 I CONTROL  [initandlisten] shutting down with code:100

I'm currently running windows 10 enterprise edition which came preinstalled with hyper-v instead of virutalbox. From what I've read virtualbox wont support the externally mapped drive for docker, but hyper-v should. I've also granted the Hyper-V Administrators user group full control of the file, as well as ensuring that docker has the drive mapped.

It can map the drive correctly, as I can run a LS command + it creates a journal folder, mongod.lock, WiredTiger, WiredTiger.lock, WiredTiger.wt, and WiredTiger.wt.1 file in the directory I mapped before it errors.

Any help would be great.

回答1:

This won't work. MongoDB and mapped volumes in Docker on Windows are not compatible, as noted for example in the mongo docker image documentation:

WARNING (Windows & OS X): The default Docker setup on Windows and OS X uses a VirtualBox VM to host the Docker daemon. Unfortunately, the mechanism VirtualBox uses to share folders between the host system and the Docker container is not compatible with the memory mapped files used by MongoDB (see vbox bug, docs.mongodb.org and related jira.mongodb.org bug). This means that it is not possible to run a MongoDB container with the data directory mapped to the host.