2

I have my docker-compose orchestration and I'm getting this error:

connection error: { MongoError: failed to connect to server [172.17.0.2:27018] on first connect [MongoError: connect ECONNREFUSED 172.17.0.2:27018]

This is the code in server.js:

mongoose.connect('mongodb://mongodb:27018');

This happen only when I customize the command of my docker container:

docker-compose.yml:

version: "3"
services:
  app:
    build: ./my-node-app
    depends_on:
      - mongodb
  mongodb:
    image: mongo:3.5
    command: mongod --port 27018

If I remove the --port 27018 and point to the default 27017 the error gets fixed.

What could be happening?

1 Answer 1

3

You're missing: --bind_ip_all

It seems that newer versions (>3.5) of the mongod daemon listen only to localhost by default.

Your are overriding this:

CMD ["mongod", "--bind_ip_all"]

So, also put "--bind_ip_all" in your docker-compose.yml:

mongodb:
  image: mongo:3.5
  command: mongod --port 27018 --bind_ip_all
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.