在windows系统使用docker运行mongoDB镜像报错,错误日志如下:
PS G:\Temp\Docker\mongodb> docker-compose up
Creating network "mongodb_default" with the default driver
Pulling mongo (mongo:)...
latest: Pulling from library/mongo
35b42117c431: Pull complete ad9c569a8d98: Pull complete 293b44f45162: Pull complete 0c175077525d: Pull complete 4e73525b52ba: Pull complete a22695a3f5e9: Pull complete c5175bcf2977: Pull complete 3e320da07793: Pull complete 01c6db6b2b5a: Pull complete 3bd6e9d03e78: Pull complete e03dcf51513f: Pull complete c1956a9e136a: Pull complete 4c35cf22b1d5: Pull complete Pulling mongo-express (mongo-express:)...
latest: Pulling from library/mongo-express
e7c96db7181b: Pull complete 5b5ce4d3d5f2: Pull complete ac289eff61bc: Pull complete 28fbd2f3252d: Pull complete 355aefc57dbb: Pull complete be052a1dc11e: Pull complete 0150ab596ec1: Pull complete 366642a63bb1: Pull complete Creating mongodb_mongo-express_1 ... done Creating mongodb_mongo_1 ... done Attaching to mongodb_mongo-express_1, mongodb_mongo_1
mongo-express_1 | Waiting for mongo:27017...
mongo-express_1 | /docker-entrypoint.sh: connect: Connection refused
mongo-express_1 | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Connection refused
mongo_1 | about to fork child process, waiting until server is ready for connections.
mongo_1 | forked process: 27
mongo_1 | 2019-07-11T13:06:43.514+0000 I CONTROL [main] ***** SERVER RESTARTED *****
mongo_1 | 2019-07-11T13:06:43.517+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
mongo_1 | 2019-07-11T13:06:43.521+0000 I CONTROL [initandlisten] MongoDB starting : pid=27 port=27017 dbpath=/data/db 64-bit host=080377f69576
mongo_1 | 2019-07-11T13:06:43.521+0000 I CONTROL [initandlisten] db version v4.0.10
mongo_1 | 2019-07-11T13:06:43.521+0000 I CONTROL [initandlisten] git version: c389e7f69f637f7a1ac3cc9fae843b635f20b766
mongo_1 | 2019-07-11T13:06:43.521+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
mongo_1 | 2019-07-11T13:06:43.521+0000 I CONTROL [initandlisten] allocator: tcmalloc
mongo_1 | 2019-07-11T13:06:43.521+0000 I CONTROL [initandlisten] modules: none
mongo_1 | 2019-07-11T13:06:43.521+0000 I CONTROL [initandlisten] build environment:
mongo_1 | 2019-07-11T13:06:43.521+0000 I CONTROL [initandlisten] distmod: ubuntu1604
mongo_1 | 2019-07-11T13:06:43.521+0000 I CONTROL [initandlisten] distarch: x86_64
mongo_1 | 2019-07-11T13:06:43.521+0000 I CONTROL [initandlisten] target_arch: x86_64
mongo_1 | 2019-07-11T13:06:43.521+0000 I CONTROL [initandlisten] options: { net: { bindIp: "127.0.0.1", port: 27017, ssl: { mode: "disabled" } }, processManagement: { fork: true, pidFilePath: "/tmp/docker-entrypoint-temp-mongod.pid" }, systemLog: { destination: "file", logAppend: true, path: "/proc/1/fd/1" } }
mongo_1 | 2019-07-11T13:06:43.526+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3474M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
mongo_1 | 2019-07-11T13:06:44.314+0000 E STORAGE [initandlisten] WiredTiger error (1) [1562850404:314622][27:0x7fbcbabdca80], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1562850404:314622][27:0x7fbcbabdca80], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
mongo_1 | 2019-07-11T13:06:44.357+0000 E STORAGE [initandlisten] WiredTiger error (17) [1562850404:357831][27:0x7fbcbabdca80], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1562850404:357831][27:0x7fbcbabdca80], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists
mongo_1 | 2019-07-11T13:06:44.360+0000 I STORAGE [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.1
mongo_1 | 2019-07-11T13:06:44.361+0000 E STORAGE [initandlisten] WiredTiger error (1) [1562850404:361857][27:0x7fbcbabdca80], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1562850404:361857][27:0x7fbcbabdca80], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
mongo_1 | 2019-07-11T13:06:44.399+0000 E STORAGE [initandlisten] WiredTiger error (17) [1562850404:399281][27:0x7fbcbabdca80], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1562850404:399281][27:0x7fbcbabdca80], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists
mongo_1 | 2019-07-11T13:06:44.401+0000 I STORAGE [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.2
mongo_1 | 2019-07-11T13:06:44.402+0000 E STORAGE [initandlisten] WiredTiger error (1) [1562850404:402727][27:0x7fbcbabdca80], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1562850404:402727][27:0x7fbcbabdca80], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
mongo_1 | 2019-07-11T13:06:44.404+0000 W STORAGE [initandlisten] Failed to start up WiredTiger under any compatibility version.
mongo_1 | 2019-07-11T13:06:44.404+0000 F STORAGE [initandlisten] Reason: 1: Operation not permitted
mongo_1 | 2019-07-11T13:06:44.404+0000 F - [initandlisten] Fatal Assertion 28595 at src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 704
mongo_1 | 2019-07-11T13:06:44.404+0000 F - [initandlisten]
mongo_1 |
mongo_1 | ***aborting after fassert() failure
mongo_1 |
mongo_1 |
......
docker-compose.yml 文件如下:
# https://hub.docker.com/_/mongo
version: '3.1'
services:
mongo:
image: mongo
restart: always
volumes:
- ./data:/data/db
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root
mongo-express:
image: mongo-express
restart: always
ports:
- 27020:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: root
通过在2台window环境下的安装的docker上尝试运行这个docker-compose.yml文件,发现都会失败,但是这个docker-compose.yml文件是基于从官网上获取的文件进行修改的,并且在自家的两台linux服务器的docker环境下都是能够正常启动的。
开始还以为是权限问题,但是观察mongo容器映射到windows磁盘中的文件夹发现,文件夹中都存在mongo启动时创建的数据库和配置等文件,应该不会是权限导致的,所以打开镜像官网,查看能否获取到一些蛛丝马迹。
通过再次阅读官网的页面,发现了注意事项中的一段内容如下:
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.
翻译一下就是:
警告(Windows和OS X):Windows和OS X上的默认Docker设置使用VirtualBox VM来托管Docker守护程序。不幸的是,VirtualBox用于在主机系统和Docker容器之间共享文件夹的机制与MongoDB使用的内存映射文件不兼容(请参阅vbox bug,docs.mongodb.org和相关的jira.mongodb.org错误)。这意味着无法运行映射到主机的数据目录的MongoDB容器。
通过其中查看参阅的链接得知:MongoDB需要一个支持fsync() 目录的文件系统。但是,HGFS和Virtual Box的共享文件夹不支持此操作。所以实际上应该是docker在window上默认使用的Virtual Box模式不支持这样的映射的操作,所以在mongodb启动的时候会报错。
目前得到的结论是,在windows系统使用docker运行mongoDB镜像的话,不要将目录映射到外部windows下。(如果有大佬有能够解决这个window下路径映射问题,欢迎留言)