Docker mongodb share volume with mac os x

后端 未结 2 2090
没有蜡笔的小新
没有蜡笔的小新 2021-02-08 05:52

I try to use the mongodb official docker image on mac os x 10.10.2 with this command inside mac terminal :

docker run -v /Users/john/data/db:/data/db -p 27017:27         


        
相关标签:
2条回答
  • 2021-02-08 06:19

    Running on the docker osx native beta (which uses xhyve rather than VirtualBox), it's now possible to mount the mongo data directory to the host system properly and without issue.

    My setup: MacBook Pro with El Capitan, Docker native beta Version 1.11.1-beta10 (build: 6662), Docker version 1.11.1, build 5604cbe

    docker run -d -p 127.0.0.1:27017:27017 -v ~/foo/data/db/:/data/db --name foo-mongo mongo
    7f8a72ec42b0ac235f49e0edd8d4f6613b45d10beb54012ca643629218a6653d
    
    docker logs foo-mongo
    2016-05-05T23:42:54.014+0000 I CONTROL  [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=7f8a72ec42b0
    2016-05-05T23:42:54.014+0000 I CONTROL  [initandlisten] db version v3.2.4
    2016-05-05T23:42:54.014+0000 I CONTROL  [initandlisten] git version: e2ee9ffcf9f5a94fad76802e28cc978718bb7a30
    2016-05-05T23:42:54.014+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013
    2016-05-05T23:42:54.014+0000 I CONTROL  [initandlisten] allocator: tcmalloc
    2016-05-05T23:42:54.014+0000 I CONTROL  [initandlisten] modules: none
    2016-05-05T23:42:54.014+0000 I CONTROL  [initandlisten] build environment:
    2016-05-05T23:42:54.014+0000 I CONTROL  [initandlisten]     distmod: debian71
    2016-05-05T23:42:54.014+0000 I CONTROL  [initandlisten]     distarch: x86_64
    2016-05-05T23:42:54.014+0000 I CONTROL  [initandlisten]     target_arch: x86_64
    2016-05-05T23:42:54.014+0000 I CONTROL  [initandlisten] options: {}
    2016-05-05T23:42:54.028+0000 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1G,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),
    2016-05-05T23:42:54.560+0000 I CONTROL  [initandlisten]
    2016-05-05T23:42:54.560+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
    2016-05-05T23:42:54.560+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
    2016-05-05T23:42:54.560+0000 I CONTROL  [initandlisten]
    2016-05-05T23:42:54.560+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
    2016-05-05T23:42:54.560+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
    2016-05-05T23:42:54.560+0000 I CONTROL  [initandlisten]
    2016-05-05T23:42:54.562+0000 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
    2016-05-05T23:42:54.562+0000 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
    2016-05-05T23:42:54.573+0000 I NETWORK  [initandlisten] waiting for connections on port 27017
    
    ls ~/foo/data/db/
    WiredTiger       WiredTiger.turtle  WiredTigerLAS.wt  collection-0-516089495343762760.wt  index-1-516089495343762760.wt  mongod.lock    storage.bson
    WiredTiger.lock  WiredTiger.wt      _mdb_catalog.wt   diagnostic.data/                    journal/                       sizeStorer.wt
    
    0 讨论(0)
  • 2021-02-08 06:26

    It seems to be specific to the mongo software and the use of virtualbox , see the mongo docker README.

    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.

    It doesn't behave like that if you keep the datadir out of the mounted volume.

    0 讨论(0)
提交回复
热议问题