来自其他容器的Docker mongo映像``连接被拒绝'' [英] Docker mongo image 'Connection refused' from other container

查看:116
本文介绍了来自其他容器的Docker mongo映像``连接被拒绝''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Docker的新手.我正在尝试创建一个MongoDB容器和一个NodeJS容器.我的文件看起来是:

I'm new to docker. I'm trying to create a MongoDB container and a NodeJS container. My file looks:

version: '2'
services:
  backend:
    image: node:5.11-onbuild
    ports:
     - "3001:3001"
    volumes:
     - .:/code
    working_dir: "/code"
    links:
     - mongodb
  mongodb:
    image: mongo:3.3
    expose:
     - 27017

它应该先运行npm install,然后运行node .. 但是docker-compose up[MongoError: connect ECONNREFUSED 127.0.0.1:27017]结尾,而命令node .. 我认为这是由于文件/etc/mongod.conf中的bind_ip = 127.0.0.1引起的.是这样吗?

It should run npm install and then node .. But docker-compose up ends up with [MongoError: connect ECONNREFUSED 127.0.0.1:27017] while the command node .. I think this is because of the bind_ip = 127.0.0.1 in the file /etc/mongod.conf. Is this right?

我在Win10系统上使用boot2docker.

I use boot2docker on a Win10 system.

如何解决此问题,以便节点可以连接到MongoDB?

How can I solve this problem so that node can connect to the MongoDB?

推荐答案

在您的后端应用中,连接到mongodb:27017而不是127.0.0.1:27017.其中"mongodb"是您在docker-compose.yml中的容器名称.

In your backend app, connect to mongodb:27017 instead of 127.0.0.1:27017. Where 'mongodb' is the name of your container within docker-compose.yml.

这篇关于来自其他容器的Docker mongo映像``连接被拒绝''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆