来自本地的Mongo Shell无法连接到在docker中运行的mongo服务器

时间:2019-04-12 10:49:45

标签: mongodb docker centos7 mongo-shell

我在docker中运行了mongo服务器,日志显示得很好。

header.vue

但是,从本地Shell连接mongodb服务器时,连接超时。

2019-04-12T10:39:51.334+0000 I CONTROL  [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=8a03346e57d7
2019-04-12T10:39:51.335+0000 I CONTROL  [initandlisten] db version v3.2.22
2019-04-12T10:39:51.335+0000 I CONTROL  [initandlisten] git version: 105acca0d443f9a47c1a5bd608fd7133840a58dd
2019-04-12T10:39:51.335+0000 I CONTROL  [initandlisten] OpenSSL version:            OpenSSL 1.0.1e-fips 11 Feb 2013
2019-04-12T10:39:51.335+0000 I CONTROL  [initandlisten] allocator: tcmalloc
2019-04-12T10:39:51.335+0000 I CONTROL  [initandlisten] modules: none
2019-04-12T10:39:51.335+0000 I CONTROL  [initandlisten] build environment:
2019-04-12T10:39:51.335+0000 I CONTROL  [initandlisten]     distmod: rhel70
2019-04-12T10:39:51.335+0000 I CONTROL  [initandlisten]     distarch: x86_64
2019-04-12T10:39:51.335+0000 I CONTROL  [initandlisten]     target_arch: x86_64
2019-04-12T10:39:51.335+0000 I CONTROL  [initandlisten] options: { net: { port: 27017 }, processManagement: { pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/data/db" } }
2019-04-12T10:39:51.339+0000 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1G,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),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),verbose=(recovery_progress),
2019-04-12T10:39:51.389+0000 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-04-12T10:39:51.389+0000 I CONTROL  [initandlisten] 
2019-04-12T10:39:51.406+0000 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2019-04-12T10:39:51.406+0000 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2019-04-12T10:39:51.406+0000 I NETWORK  [initandlisten] waiting for connections on port 27017

其中172.17.0.2是通过运行~/mongodb/bin/mongo --host 172.17.0.2 MongoDB shell version v3.6.11 connecting to: mongodb://172.17.0.2:27017/?gssapiServiceName=mongodb 2019-04-12T16:04:45.750+0530 W NETWORK [thread1] Failed to connect to 172.17.0.2:27017 after 5000ms milliseconds, giving up. 2019-04-12T16:04:45.753+0530 E QUERY [thread1] Error: couldn't connect to server 172.17.0.2:27017, connection attempt failed : connect@src/mongo/shell/mongo.js:263:13 @(connect):1:6 exception: connect failed

获得的IP

我能够使用命令docker inspect <container-id在docker中连接mongo shell。 这是供参考的Docker文件。

docker exec --it <container-id> bash

让我知道我是否想念一些东西。 使用MacOS

0 个答案:

没有答案