关于widows系统使用docker部署mongo时报错:Operation not permitted

踩坑过程

想要在window环境下部署一个基于docker的mongoDB环境,在做数据持久化过程中,发现将主机目录映射到docker中运行mongo镜像,报了一个错。

错误提示:Operation not permitted.(不允许操作),一开始以为是文件夹权限的问题,于是给了主机目录足够权限依然是报这个错误。

2019-08-15T14:23:53.429+0000 I  CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-08-15T14:23:53.442+0000 I  CONTROL  [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=8ee8b85762fb
2019-08-15T14:23:53.442+0000 I  CONTROL  [initandlisten] db version v4.2.0
2019-08-15T14:23:53.442+0000 I  CONTROL  [initandlisten] git version: a4b751dcf51dd249c5865812b390cfd1c0129c30
2019-08-15T14:23:53.442+0000 I  CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
2019-08-15T14:23:53.442+0000 I  CONTROL  [initandlisten] allocator: tcmalloc
2019-08-15T14:23:53.442+0000 I  CONTROL  [initandlisten] modules: none
2019-08-15T14:23:53.442+0000 I  CONTROL  [initandlisten] build environment:
2019-08-15T14:23:53.442+0000 I  CONTROL  [initandlisten]     distmod: ubuntu1804
2019-08-15T14:23:53.442+0000 I  CONTROL  [initandlisten]     distarch: x86_64
2019-08-15T14:23:53.442+0000 I  CONTROL  [initandlisten]     target_arch: x86_64
2019-08-15T14:23:53.442+0000 I  CONTROL  [initandlisten] options: { net: { bindIp: "*" } }
2019-08-15T14:23:53.451+0000 I  STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1452M,cache_overflow=(file_max=0M),session_max=33000,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,checkpoint_progress],
2019-08-15T14:23:54.311+0000 E  STORAGE  [initandlisten] WiredTiger error (1) [1565879034:311033][1:0x7f81e32aeb00], connection: __posix_open_file, 712: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1565879034:311033][1:0x7f81e32aeb00], connection: __posix_open_file, 712: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
2019-08-15T14:23:54.406+0000 E  STORAGE  [initandlisten] WiredTiger error (17) [1565879034:406436][1:0x7f81e32aeb00], connection: __posix_open_file, 712: /data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1565879034:406436][1:0x7f81e32aeb00], connection: __posix_open_file, 712: /data/db/WiredTiger.wt: handle-open: open: File exists
2019-08-15T14:23:54.417+0000 I  STORAGE  [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.1
2019-08-15T14:23:54.429+0000 E  STORAGE  [initandlisten] WiredTiger error (1) [1565879034:429381][1:0x7f81e32aeb00], connection: __posix_open_file, 712: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1565879034:429381][1:0x7f81e32aeb00], connection: __posix_open_file, 712: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
2019-08-15T14:23:54.520+0000 E  STORAGE  [initandlisten] WiredTiger error (17) [1565879034:520759][1:0x7f81e32aeb00], connection: __posix_open_file, 712: /data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1565879034:520759][1:0x7f81e32aeb00], connection: __posix_open_file, 712: /data/db/WiredTiger.wt: handle-open: open: File exists
2019-08-15T14:23:54.524+0000 I  STORAGE  [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.2
2019-08-15T14:23:54.526+0000 E  STORAGE  [initandlisten] WiredTiger error (1) [1565879034:526219][1:0x7f81e32aeb00], connection: __posix_open_file, 712: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1565879034:526219][1:0x7f81e32aeb00], connection: __posix_open_file, 712: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
2019-08-15T14:23:54.529+0000 W  STORAGE  [initandlisten] Failed to start up WiredTiger under any compatibility version.
2019-08-15T14:23:54.530+0000 F  STORAGE  [initandlisten] Reason: 1: Operation not permitted
2019-08-15T14:23:54.530+0000 F  -        [initandlisten] Fatal Assertion 28595 at src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 783
2019-08-15T14:23:54.530+0000 F  -        [initandlisten]

***aborting after fassert() failure

错误原因

后来,在Docker Hub中mongoDB官方镜像上,发现了有关导致这个错误的原因。

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 bugdocs.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容器。

解决方案

使用docker的数据卷(Volume)作为保存持久化数据的目录,数据卷Volume可理解为虚拟磁盘。

创建Volume虚拟磁盘:docker volume create --name <名称>

删除Volume虚拟磁盘:docker volume rm <名称>

docker volume create --name mongodata
docker run --name mongodb -v mongodata:/data/db -p 27017:27017 -d mongo:latest

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章