Cannot connect from inside docker swarm cluster to external mongodb service
NickName:Dmytro Nalyvaiko Ask DateTime:2017-06-23T00:05:21

Cannot connect from inside docker swarm cluster to external mongodb service

If I run single docker container of my backend, it runs well and connects to mongodb which is running on host. But when I run my backend using docker-compose, it doesn't connect to mongodb and prints to console:

MongoError: failed to connect to server [12.345.678.912:27017] on first connect [MongoError: connection 0 to 12.345.678.912:27017 timed out]

docker-compose.yml contents:

version: "3"
services:
  web:
    image: __BE-IMAGE__
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
      resources:
        limits:
          cpus: "0.1"
          memory: 2048M
    ports:
      - "1337:8080"
    networks:
      - webnet
  visualizer:
    image: dockersamples/visualizer:stable
    ports:
      - "1340:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    deploy:
      placement:
        constraints: [node.role == manager]
    networks:
      - webnet
networks:
  webnet:

how I run single docker container:

docker run -p 1337:8080 BE-IMAGE

Copyright Notice:Content Author:「Dmytro Nalyvaiko」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/44704450/cannot-connect-from-inside-docker-swarm-cluster-to-external-mongodb-service

More about “Cannot connect from inside docker swarm cluster to external mongodb service” related questions

Nginx configuration for connecting to external mongodb from docker swarm

I have a docker swarm running 2 python flask services, each one running in a different region, say A, and B. Region A is also running Nginx, which is the main entrypoint to access the services. The...

Show Detail

How to connect to another docker service from one docker service in a docker swarm cluster?

In the docker swarm cluster, launched two services: sv_web sv_api The stack deploy file of web is: version: "3" services: web: image: XXX/sv_web:latest ports: - "80:80"

Show Detail

Cannot access a Docker Swarm service through its published port on the host

I have deployed a Docker Swarm cluster on several machines and I am now trying to access to the server running in Docker from the host. I use docker compose file to define my service and the exposed

Show Detail

Cannot connect from inside docker swarm cluster to external mongodb service

If I run single docker container of my backend, it runs well and connects to mongodb which is running on host. But when I run my backend using docker-compose, it doesn't connect to mongodb and prin...

Show Detail

Unable to access service running in docker swarm cluster

I have a docker swarm cluster with following nodes NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS manager1 - virtualbox Running tcp:/...

Show Detail

Zerotier running in a Docker Swarm Service

I have a docker swarm with 3 nodes. Each node has a mongodb service running. I want to be able to connect to the database using Robo 3T from my local device, but I don't want to expose any ports. Is

Show Detail

Redis cluster with docker swarm using docker compose

I'm just learning docker and all of its goodness like swarm and compose. My intention is to create a Redis cluster in docker swarm. Here is my compose file - version: '3' services: redis: ...

Show Detail

Cannot connect node js app to mongodb running in a docker swarm

I am trying to deploy nodejs app in docker swarm. However I'm struggling to make it connect to the mongodb service. Below is my docker-compose file version: '3' services: moitrack-teltonika-parse...

Show Detail

Docker Swarm Service IP High-availability

I've built a docker swarm cluster (6 nodes). Although I was able to build resilient services (several nodes answering requests for the same service with several instances), I cannot find a way to b...

Show Detail

Creating a swarm cluster with Docker for Mac

I've been trying to follow this tutorial: https://docs.docker.com/engine/swarm/swarm-tutorial/ Instead of running it on some real linux hosts or local VMs I want to network a couple of MacBooks ru...

Show Detail