我是docker新手,所以我在Windows 10上安装了docker。在docker中,我有mongo容器:
>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0958a1225102 63c6b736e399 "docker-entrypoint.s…" 17 hours ago Up About an hour 0.0.0.0:27017->27017/tcp mongo
在我的计算机上,我有mongodb的数据库备份。我的问题是如何在docker内部使用 mongodump 来恢复docker外部的mongo数据库?
我至今没有任何想法,因此,我正在谷歌上搜索,发现自己必须在docker中使用link
。
这是我的docker图片:
docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 63c6b736e399 3 days ago 379MB
mdillon/postgis latest a6ca3144c3c6 5 weeks ago 630MB
<none> <none> 31b9bde409bb 5 weeks ago 238MB
docker4w/nsenter-dockerd latest cae870735e91 9 months ago 187kB
此图片ID 63c6b736e399 是Mongo。
这是我的容器:
>docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0958a1225102 63c6b736e399 "docker-entrypoint.s…" 18 hours ago Up About an hour 0.0.0.0:27017->27017/tcp mongo
4626c2d9df9a 31b9bde409bb "/entrypoint.sh" 21 hours ago Exited (0) 21 hours ago kind_archimedes
34ff3510b916 31b9bde409bb "/entrypoint.sh" 22 hours ago Exited (0) 22 hours ago determined_montalcini
36f5de645426 mdillon/postgis "docker-entrypoint.s…" 22 hours ago Exited (137) 21 hours ago pg
我已经在用户C:\Users\Groot\dump
上创建了一个文件夹,并在docker上使用了以下命令:
>docker run --rm --link 63c6b736e399:<none> -v /C/Users/Groot/dump:backup mongo bash -c "mongodump /backup --host mongo:27017"
The system cannot find the file specified.
但是我得到了这个错误:
The system cannot find the file specified.
所以我决定使用其他方式(使用绑定挂载)
我以这种方式创建了mongo容器:
docker run -p 27017:27017 --name mongo -v /C/Users/Groot/Mongodb/db:\data\db -d 63c6b736e399
一切正常:
2018-08-03T01:45:47.335+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-08-03T01:45:47.339+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=0958a1225102
2018-08-03T01:45:47.339+0000 I CONTROL [initandlisten] db version v4.0.0
2018-08-03T01:45:47.339+0000 I CONTROL [initandlisten] git version: 3b07af3d4f471ae89e8186d33bbb1d5259597d51
2018-08-03T01:45:47.339+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2018-08-03T01:45:47.339+0000 I CONTROL [initandlisten] allocator: tcmalloc
2018-08-03T01:45:47.339+0000 I CONTROL [initandlisten] modules: none
2018-08-03T01:45:47.339+0000 I CONTROL [initandlisten] build environment:
2018-08-03T01:45:47.339+0000 I CONTROL [initandlisten] distmod: ubuntu1604
2018-08-03T01:45:47.339+0000 I CONTROL [initandlisten] distarch: x86_64
2018-08-03T01:45:47.339+0000 I CONTROL [initandlisten] target_arch: x86_64
2018-08-03T01:45:47.339+0000 I CONTROL [initandlisten] options: { net: { bindIpAll: true } }
2018-08-03T01:45:47.339+0000 I STORAGE [initandlisten]
2018-08-03T01:45:47.339+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2018-08-03T01:45:47.339+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2018-08-03T01:45:47.339+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=478M,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),
2018-08-03T01:45:48.230+0000 I STORAGE [initandlisten] WiredTiger message [1533260748:230085][1:0x7f4005248a00], txn-recover: Set global recovery timestamp: 0
2018-08-03T01:45:48.523+0000 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2018-08-03T01:45:48.976+0000 I CONTROL [initandlisten]
2018-08-03T01:45:48.976+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-08-03T01:45:48.976+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-08-03T01:45:48.976+0000 I CONTROL [initandlisten]
2018-08-03T01:45:48.976+0000 I STORAGE [initandlisten] createCollection: admin.system.version with provided UUID: a974cc90-9be3-4176-831b-a6b664e82dbe
2018-08-03T01:45:49.414+0000 I COMMAND [initandlisten] setting featureCompatibilityVersion to 4.0
2018-08-03T01:45:49.421+0000 I STORAGE [initandlisten] createCollection: local.startup_log with generated UUID: 7e13557b-16e6-40d0-9252-050161213541
2018-08-03T01:45:49.765+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2018-08-03T01:45:49.767+0000 I NETWORK [initandlisten] waiting for connections on port 27017
2018-08-03T01:45:49.767+0000 I STORAGE [LogicalSessionCacheRefresh] createCollection: config.system.sessions with generated UUID: 27ef2e39-a402-4a4d-86bc-d37fe84b48aa
2018-08-03T01:45:50.213+0000 I INDEX [LogicalSessionCacheRefresh] build index on: config.system.sessions properties: { v: 2, key: { lastUse: 1 }, name: "lsidTTLIndex", ns: "config.system.sessions", expireAfterSeconds: 1800 }
2018-08-03T01:45:50.213+0000 I INDEX [LogicalSessionCacheRefresh] building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2018-08-03T01:45:50.215+0000 I INDEX [LogicalSessionCacheRefresh] build index done. scanned 0 total records. 0 secs
2018-08-03T01:45:50.215+0000 I COMMAND [LogicalSessionCacheRefresh] command config.$cmd command: createIndexes { createIndexes: "system.sessions", indexes: [ { key: { lastUse: 1 }, name: "lsidTTLIndex", expireAfterSeconds: 1800 } ], $db: "config" } numYields:0 reslen:114 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { W: 1 } }, Collection: { acquireCount: { w: 1 } } } protocol:op_msg 448ms
2018-08-03T01:46:31.061+0000 I NETWORK [listener] connection accepted from 172.17.0.1:60158 #1 (1 connection now open)
2018-08-03T01:46:31.061+0000 I NETWORK [conn1] received client metadata from 172.17.0.1:60158 conn1: { application: { name: "robo3t" }, driver: { name: "MongoDB Internal Client", version: "3.4.3-10-g865d2fb" }, os: { type: "Windows", name: "Microsoft Windows 8", architecture: "x86_64", version: "6.2 (build 9200)" } }
2018-08-03T01:46:31.113+0000 I NETWORK [listener] connection accepted from 172.17.0.1:60160 #2 (2 connections now open)
2018-08-03T01:46:31.113+0000 I NETWORK [conn2] received client metadata from 172.17.0.1:60160 conn2: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.3-10-g865d2fb" }, os: { type: "Windows", name: "Microsoft Windows 8", architecture: "x86_64", version: "6.2 (build 9200)" } }
2018-08-03T01:46:35.610+0000 I NETWORK [conn2] end connection 172.17.0.1:60160 (1 connection now open)
2018-08-03T01:46:35.610+0000 I NETWORK [conn1] end connection 172.17.0.1:60158 (0 connections now open)
2018-08-03T01:48:48.228+0000 I NETWORK [listener] connection accepted from 172.17.0.1:60162 #3 (1 connection now open)
2018-08-03T01:48:48.229+0000 I NETWORK [conn3] received client metadata from 172.17.0.1:60162 conn3: { application: { name: "robo3t" }, driver: { name: "MongoDB Internal Client", version: "3.4.3-10-g865d2fb" }, os: { type: "Windows", name: "Microsoft Windows 8", architecture: "x86_64", version: "6.2 (build 9200)" } }
2018-08-03T01:48:48.283+0000 I NETWORK [listener] connection accepted from 172.17.0.1:60164 #4 (2 connections now open)
2018-08-03T01:48:48.291+0000 I NETWORK [conn4] received client metadata from 172.17.0.1:60164 conn4: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.3-10-g865d2fb" }, os: { type: "Windows", name: "Microsoft Windows 8", architecture: "x86_64", version: "6.2 (build 9200)" } }
2018-08-03T01:49:04.756+0000 I NETWORK [conn4] end connection 172.17.0.1:60164 (1 connection now open)
2018-08-03T01:49:04.756+0000 I NETWORK [conn3] end connection 172.17.0.1:60162 (0 connections now open)
2018-08-03T04:30:50.300+0000 I CONTROL [signalProcessingThread] got signal 15 (Terminated), will terminate after current cmd ends
2018-08-03T04:30:50.300+0000 I NETWORK [signalProcessingThread] shutdown: going to close listening sockets...
2018-08-03T04:30:50.300+0000 I NETWORK [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
2018-08-03T04:30:50.300+0000 I CONTROL [signalProcessingThread] Shutting down free monitoring
2018-08-03T04:30:50.300+0000 I FTDC [signalProcessingThread] Shutting down full-time diagnostic data capture
2018-08-03T04:30:50.302+0000 I STORAGE [signalProcessingThread] WiredTigerKVEngine shutting down
2018-08-03T04:30:50.697+0000 I STORAGE [signalProcessingThread] shutdown: removing fs lock...
2018-08-03T04:30:50.697+0000 I CONTROL [signalProcessingThread] now exiting
2018-08-03T04:30:50.697+0000 I CONTROL [signalProcessingThread] shutting down with code:0
2018-08-03T18:11:05.045+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-08-03T18:11:05.049+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=0958a1225102
2018-08-03T18:11:05.049+0000 I CONTROL [initandlisten] db version v4.0.0
2018-08-03T18:11:05.049+0000 I CONTROL [initandlisten] git version: 3b07af3d4f471ae89e8186d33bbb1d5259597d51
2018-08-03T18:11:05.049+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2018-08-03T18:11:05.049+0000 I CONTROL [initandlisten] allocator: tcmalloc
2018-08-03T18:11:05.049+0000 I CONTROL [initandlisten] modules: none
2018-08-03T18:11:05.049+0000 I CONTROL [initandlisten] build environment:
2018-08-03T18:11:05.049+0000 I CONTROL [initandlisten] distmod: ubuntu1604
2018-08-03T18:11:05.049+0000 I CONTROL [initandlisten] distarch: x86_64
2018-08-03T18:11:05.049+0000 I CONTROL [initandlisten] target_arch: x86_64
2018-08-03T18:11:05.049+0000 I CONTROL [initandlisten] options: { net: { bindIpAll: true } }
2018-08-03T18:11:05.050+0000 I STORAGE [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-08-03T18:11:05.050+0000 I STORAGE [initandlisten]
2018-08-03T18:11:05.050+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2018-08-03T18:11:05.050+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2018-08-03T18:11:05.050+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=478M,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),
2018-08-03T18:11:05.845+0000 I STORAGE [initandlisten] WiredTiger message [1533319865:845615][1:0x7f198b6efa00], txn-recover: Main recovery loop: starting at 1/27776
2018-08-03T18:11:05.925+0000 I STORAGE [initandlisten] WiredTiger message [1533319865:925154][1:0x7f198b6efa00], txn-recover: Recovering log 1 through 2
2018-08-03T18:11:06.021+0000 I STORAGE [initandlisten] WiredTiger message [1533319866:21800][1:0x7f198b6efa00], txn-recover: Recovering log 2 through 2
2018-08-03T18:11:06.061+0000 I STORAGE [initandlisten] WiredTiger message [1533319866:61163][1:0x7f198b6efa00], txn-recover: Set global recovery timestamp: 0
2018-08-03T18:11:06.525+0000 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2018-08-03T18:11:06.707+0000 I CONTROL [initandlisten]
2018-08-03T18:11:06.707+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-08-03T18:11:06.707+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-08-03T18:11:06.707+0000 I CONTROL [initandlisten]
2018-08-03T18:11:06.810+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2018-08-03T18:11:06.811+0000 I NETWORK [initandlisten] waiting for connections on port 27017
和:
"Mounts": [
{
"Type": "bind",
"Source": "/host_mnt/c/Users/Groot/Mongodb/db",
"Destination": "\\data\\db",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},
现在,我将备份数据库放入此文件夹:
C:\Users\Groot\Mongodb\db
然后进入mongo bash。如您所见,我在/ data / db上看不到任何Users.bson
文件:
/# ls
\data\db data etc lib mnt root srv usr
bin dev home lib64 opt run sys var
boot docker-entrypoint-initdb.d js-yaml.js media proc sbin tmp
和:
:/data/db# ls
WiredTiger diagnostic.data
WiredTiger.lock index-1-8299742026059345422.wt
WiredTiger.turtle index-3-8299742026059345422.wt
WiredTiger.wt index-5-8299742026059345422.wt
WiredTigerLAS.wt index-6-8299742026059345422.wt
_mdb_catalog.wt journal
collection-0-8299742026059345422.wt mongod.lock
collection-2-8299742026059345422.wt sizeStorer.wt
collection-4-8299742026059345422.wt storage.bson
这是C:\Users\Groot\Mongodb\db
:
C:\Users\Groot\Mongodb\db>dir
Volume in drive C has no label.
Volume Serial Number is 1C77-2E2C
Directory of C:\Users\Groot\Mongodb\db
08/03/2018 12:35 PM <DIR> .
08/03/2018 12:35 PM <DIR> ..
06/20/2017 11:35 PM 1,143 Users.bson
06/20/2017 11:35 PM 86 Users.metadata.json
2 File(s) 1,229 bytes
2 Dir(s) 77,444,005,888 bytes free
这是怎么回事?我的错误在哪里?