简体   繁体   中英

Connection slow from node to mongodb

I'm experimenting with docker and reflected a very slow connection from the nodejs (4.2.3) container to mongodb (3.2) container.

My setup, very basic, is this (docker-compose):

version: '2'

services:
  web:
    build: ./app
    volumes:
      - "./app:/src/app"
    ports:
      - "80:3000"
    links:
      - "db_cache:redis"
      - "db:mongodb"
    command: nodemon -L app/bin/www

  db_cache:
    image: redis
  db:
    image: mongo

My so is OSX 10.10 and the docker version is 1.10.2.

The strange thing is that the connection time to the db is always 30 seconds.

Is there any automatic delay?

EDIT:

if I set ip address of mongodb container intead a "dns" ( mongodb ), the delay disappears!

Any ideas?

This does not completely solve the problem, but it allows you to restore the normal behavior.

The cause of this seems to be the version 2 of the docker-compose.yml .

If I remove the version 2 is completely eliminated the 30-second delay when connecting to mongodb:

web:
  build: ./app
  volumes:
    - "./app:/src/app"
  ports:
    - "80:3000"
  links:
    - "db_cache:redis"
    - "db:mongodb"
  command: nodemon -L app/bin/www

db_cache:
  image: redis
db:
  image: mongo

I opened an issue here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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