简体   繁体   English

无法连接到docker mongo

[英]Cannot connect to docker mongo

I am setting up a project using sane with docker. 我正在与docker一起使用健全的项目。 After creating the project to use mongodb and createing a resource I tried running it, but got an error reporting that the server container could not connect to mongo. 在创建使用mongodb的项目并创建资源后,我尝试运行它,但是收到一条错误消息,报告服务器容器无法连接到mongo。 I then tried just running fig up to see if it was a fig problem and got the same error. 然后,我尝试仅运行fig up ,看看是否是无花果问题,并得到相同的错误。 Here is my fig.yml (irrelevant comments removed): 这是我的fig.yml (删除了不相关的注释):

db:
  image: mongo:latest
  ports:
    - "27017:27017"
server:
  image: artificial/docker-sails:stable-pm2
  command: sails lift
  volumes:
    - server/:/server
  ports:
    - "1337:1337"
  links:
    - db

The full error report on fig up is as follows (the error report on sane up is the same, although the output from db_1 is more terse and there are also lines of output for the client): 关于fig up的完整错误报告如下(关于sane up的错误报告是相同的,尽管db_1的输出更简洁,并且客户端也有输出行):

Recreating hydro_db_1...
Recreating hydro_server_1...
Attaching to hydro_db_1, hydro_server_1
db_1     | mongod --help for help and startup options
db_1     | 2015-02-17T13:32:00.092+0000 [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=b7a85ddb94e2
db_1     | 2015-02-17T13:32:00.093+0000 [initandlisten] db version v2.6.7
db_1     | 2015-02-17T13:32:00.094+0000 [initandlisten] git version: a7d57ad27c382de82e9cb93bf983a80fd9ac9899
db_1     | 2015-02-17T13:32:00.094+0000 [initandlisten] build info: Linux build7.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
db_1     | 2015-02-17T13:32:00.094+0000 [initandlisten] allocator: tcmalloc
db_1     | 2015-02-17T13:32:00.094+0000 [initandlisten] options: {}
db_1     | 2015-02-17T13:32:00.099+0000 [initandlisten] journal dir=/data/db/journal
db_1     | 2015-02-17T13:32:00.099+0000 [initandlisten] recover : no journal files present, no recovery needed
db_1     | 2015-02-17T13:32:00.274+0000 [initandlisten] waiting for connections on port 27017
server_1 | 
server_1 | info: Starting app...
server_1 | 
server_1 | error: A hook (`orm`) failed to load!
server_1 | error: Error: Failed to connect to MongoDB.  Are you sure your configured Mongo instance is running?
server_1 |  Error details:
server_1 | [Error: failed to connect to [localhost:27017]]
server_1 |     at _createError (/server/node_modules/sails-mongo/lib/adapter.js:98:23)
server_1 |     at /server/node_modules/sails-mongo/lib/adapter.js:101:13
server_1 |     at /server/node_modules/sails-mongo/lib/connection.js:25:20
server_1 |     at /server/node_modules/sails-mongo/node_modules/mongodb/lib/mongodb/mongo_client.js:406:11
server_1 |     at process._tickDomainCallback (node.js:486:13) { [Error: Failed to connect to MongoDB.  Are you sure your configured Mongo instance is running?
server_1 |  Error details:
server_1 | [Error: failed to connect to [localhost:27017]]]
server_1 |   originalError: [Error: failed to connect to [localhost:27017]] }
server_1 | error: Error: Failed to connect to MongoDB.  Are you sure your configured Mongo instance is running?
server_1 |  Error details:
server_1 | [Error: failed to connect to [localhost:27017]]
server_1 |     at _createError (/server/node_modules/sails-mongo/lib/adapter.js:98:23)
server_1 |     at /server/node_modules/sails-mongo/lib/adapter.js:101:13
server_1 |     at /server/node_modules/sails-mongo/lib/connection.js:25:20
server_1 |     at /server/node_modules/sails-mongo/node_modules/mongodb/lib/mongodb/mongo_client.js:406:11
server_1 |     at process._tickDomainCallback (node.js:486:13) { [Error: Failed to connect to MongoDB.  Are you sure your configured Mongo instance is running?
server_1 |  Error details:
server_1 | [Error: failed to connect to [localhost:27017]]]
server_1 |   originalError: [Error: failed to connect to [localhost:27017]] }
hydro_server_1 exited with code 1
Gracefully stopping... (press Ctrl+C again to force)
Stopping hydro_db_1...

I'm not sure if this is a docker problem, a fig problem, a sane problem, or a sails problem. 我不确定这是码头工人问题,无花果问题,理智问题还是帆问题。 I also cannot figure out how to fix it. 我也无法弄清楚如何解决它。

Replace localhost with the mongo container IP, which you should be able to get from an environment variable that Docker will populate for you. 将mongo容器IP替换为localhost ,您应该能够从Docker将为您填充的环境变量中获取该IP。

Docker will also set up an entry for db in /etc/hosts that you can use. Docker还将在/etc/hosts中为您可以使用的db设置一个条目。

I'm running MongoDB through Docker, and I got it to work with this: 我正在通过Docker运行MongoDB,并且可以使用它:

$ export dockerip="$(docker-machine ls | awk '{print $5}' | sed -n '2p' | sed 's/tcp:\/\///' | sed 's/\:2376//')"
$ mongo --host "$dockerip" --port 27017

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM