關於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

 

 

 

 

 

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