如何将 Docker 容器中的 MongoDB 数据挂载到 Windows 10 上的本地存储?

huangapple go评论105阅读模式
英文:

How to mount mongodb data from docker container to localhost storage on Windows 10?

问题

当我尝试使用以下命令为Mongo创建卷时:

docker run -p 27015:27017 -v C:\myPath\mongodump:/data/db mongo

我遇到了错误:

  1. 2020-01-03T10:08:58.002+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
  2. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=bab5c142014f
  3. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] db version v4.2.2
  4. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
  5. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
  6. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] allocator: tcmalloc
  7. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] modules: none
  8. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] build environment:
  9. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] distmod: ubuntu1804
  10. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] distarch: x86_64
  11. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] target_arch: x86_64
  12. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] options: { net: { bindIp: "*" } }
  13. 2020-01-03T10:08:58.018+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=478M,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,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
  14. 2020-01-03T10:08:58.613+0000 E STORAGE [initandlisten] WiredTiger error (1) [1578046138:613590][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1578046138:613590][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
  15. 2020-01-03T10:08:58.628+0000 E STORAGE [initandlisten] WiredTiger error (17) [1578046138:628759][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1578046138:628759][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: File exists
  16. 2020-01-03T10:08:58.632+0000 I STORAGE [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.1
  17. 2020-01-03T10:08:58.637+0000 E STORAGE [initandlisten] WiredTiger error (1) [1578046138:637909][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1578046138:637909][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
  18. 2020-01-03T10:08:58.650+0000 E STORAGE [initandlisten] WiredTiger error (17) [1578046138:650974][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1578046138:650974][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: File exists
  19. 2020-01-03T10:08:58.655+0000 I STORAGE [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.2
  20. 2020-01-03T10:08:58.660+0000 E STORAGE [initandlisten] WiredTiger error (1) [1578046138:660725][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1578046138:660725][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
  21. 2020-01-03T10:08:58.663+0000 W STORAGE [initandlisten] Failed to start up WiredTiger under any compatibility version.
  22. 2020-01-03T10:08:58.663+0000 F STORAGE [initandlisten] Reason: 1: Operation not permitted
  23. 2020-01-03T10:08:58.663+0000 F - [initandlisten] Fatal Assertion 28595
  24. <details>
  25. <summary>英文:</summary>
  26. When I try to create volume for mongo using below command:
  27. **docker run -p 27015:27017 -v C:\myPath\mongodump:/data/db mongo**
  28. I get the error:
  29. 2020-01-03T10:08:58.002+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols &#39;none&#39;
  30. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=bab5c142014f
  31. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] db version v4.2.2
  32. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
  33. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
  34. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] allocator: tcmalloc
  35. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] modules: none
  36. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] build environment:
  37. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] distmod: ubuntu1804
  38. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] distarch: x86_64
  39. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] target_arch: x86_64
  40. 2020-01-03T10:08:58.006+0000 I CONTROL [initandlisten] options: { net: { bindIp: &quot;*&quot; } }
  41. 2020-01-03T10:08:58.018+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=478M,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,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
  42. 2020-01-03T10:08:58.613+0000 E STORAGE [initandlisten] WiredTiger error (1) [1578046138:613590][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1578046138:613590][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
  43. 2020-01-03T10:08:58.628+0000 E STORAGE [initandlisten] WiredTiger error (17) [1578046138:628759][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1578046138:628759][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: File exists
  44. 2020-01-03T10:08:58.632+0000 I STORAGE [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.1
  45. 2020-01-03T10:08:58.637+0000 E STORAGE [initandlisten] WiredTiger error (1) [1578046138:637909][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1578046138:637909][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
  46. 2020-01-03T10:08:58.650+0000 E STORAGE [initandlisten] WiredTiger error (17) [1578046138:650974][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1578046138:650974][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: File exists
  47. 2020-01-03T10:08:58.655+0000 I STORAGE [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.2
  48. 2020-01-03T10:08:58.660+0000 E STORAGE [initandlisten] WiredTiger error (1) [1578046138:660725][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1578046138:660725][1:0x7f596d6b6b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
  49. 2020-01-03T10:08:58.663+0000 W STORAGE [initandlisten] Failed to start up WiredTiger under any compatibility version.
  50. 2020-01-03T10:08:58.663+0000 F STORAGE [initandlisten] Reason: 1: Operation not permitted
  51. 2020-01-03T10:08:58.663+0000 F - [initandlisten] Fatal Assertion 28595 at src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 789
  52. 2020-01-03T10:08:58.663+0000 F - [initandlisten]
  53. ***aborting after fassert() failure
  54. Related document says that it is because the Docker container is not compatible with the memory mapped files used by MongoDB. info: https://hub.docker.com/_/mongo .
  55. Is there anyway to make mongodb volume mounting possible in windows?Or any other work around to just take mongo dump to local storage automatically (How to write it in docker-compose file)?
  56. </details>
  57. # 答案1
  58. **得分**: 3
  59. docker只能通过Linux文件系统访问。
  60. 要解决这个问题,您需要单独创建卷。
  61. 如下所示。请参阅此[链接][1]。
  62. ```shell
  63. docker volume create --name=mongodata
  64. docker run -d -p 27015:27017 -v mongodata:/data/db mongo
英文:

docker can only be accessed through the linux file system.

To solve this problem, you have to create volume separately.

like below. and please see this link

  1. docker volume create --name=mongodata
  2. docker run -d -p 27015:27017 -v mongodata:/data/db mongo

答案2

得分: 1

如果有人也遇到相同的问题,但是使用Docker Compose,以下解决方案修复了我的问题:

  1. version: '3.3'
  2. services:
  3. mongodb:
  4. image: mongo
  5. container_name: mongodb
  6. volumes:
  7. - mongodata:/data/db
  8. ports:
  9. - 27017:27017
  10. volumes:
  11. mongodata:

参考链接

这也适用于版本2.3的Compose文件版本。

英文:

@r_zelazny
If anyone is also having the same error but with docker compose, the following solution fixed my problem

  1. version: &#39;3.3&#39;
  2. services:
  3. mongodb:
  4. image: mongo
  5. container_name: mongodb
  6. volumes:
  7. - mongodata:/data/db
  8. ports:
  9. - 27017:27017
  10. volumes:
  11. mongodata:

Reference

This also works with version 2.3 compose file version

答案3

得分: 0

这在Windows上对我有效

  1. 创建文件夹 C:/mongodb/db

  2. 运行以下代码

  1. version: '3.1'
  2. services:
  3. mongodb:
  4. image: mongo
  5. ports:
  6. - 27018:27017
  7. environment:
  8. MONGO_INITDB_ROOT_USERNAME: user
  9. MONGO_INITDB_ROOT_PASSWORD: pass
  10. volumes:
  11. - C:/mongodb/db:/data/db

所有数据库数据将存储在 C:/mongodb/db,使数据在Windows上持久化

谢谢!

英文:

This work for me on windows

  1. Create the folder &#39;C:/mongodb/db&#39;

  2. Run the next code with
    docker stack deploy -c stack.yml test

  1. services:
  2. mongodb:
  3. image: mongo
  4. ports:
  5. - 27018:27017
  6. environment:
  7. MONGO_INITDB_ROOT_USERNAME: user
  8. MONGO_INITDB_ROOT_PASSWORD: pass
  9. volumes:
  10. - C:/mongodb/db:/data/db

All data from the database will be stored in &#39;C:/mongodb/db&#39; making the data persistent for windows

Regards!!

huangapple
  • 本文由 发表于 2020年1月3日 20:36:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578766.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定