Search code examples
docker-composedocker-swarmportainer

UnhandledPromiseRejectionWarning: Error: getaddrinfo ENOTFOUND in nodejs running on docker-swarm


As you can find below from the docker-compose.yml file which is hosted in Portainer Stack on Docker-Swarm mode. The Containers are running fine in Portainer but it looks like the lamp-server is unable to communicate with the Redis and throwing the following error:

(node:1) UnhandledPromiseRejectionWarning: Error: getaddrinfo ENOTFOUND cache
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)

Here is my configuration:

enter image description here

version: '3.7'
services:
  server:
    image: 'bidmcdigitalpsychiatry/lamp-server:latest'
    environment:
      - HTTPS=off
      - SCHEDULER=on
      - ROOT_KEY=xxxx
      - CDB=http://admin:xxxx@database:5984/  
      - PUSH_API_GATEWAY=xxxx
      - PUSH_API_KEY=xxxx   
      - REDIS_HOST=redis://cache:6379/0
      - NATS_SERVER=message_queue:4222
    networks:
      - public
    deploy:
      mode: replicated
      labels:
        traefik.enable: 'true'
        traefik.http.routers.lamp_server.entryPoints: 'websecure'
        traefik.http.routers.lamp_server.rule: 'Host(`api.example.com`)'
        traefik.http.routers.lamp_server.tls.certresolver: 'default'
        traefik.http.services.lamp_server.loadbalancer.server.port: 3000
      placement:
        constraints:
          - node.role == manager
  database:
    image: apache/couchdb:latest
    volumes:
      - /home/azureuser/data/couchdb:/opt/couchdb/data
    networks:
      - public
    environment:
       - COUCHDB_USER=admin
       - COUCHDB_PASSWORD=xxxxx
    deploy:
      mode: replicated
      labels:
        traefik.enable: 'true'
        traefik.http.routers.lamp_db.entryPoints: 'websecure'
        traefik.http.routers.lamp_db.rule: 'Host(`db.example.com`)'
        traefik.http.routers.lamp_db.tls.certresolver: 'default'
        traefik.http.services.lamp_db.loadbalancer.server.port: 5984
      placement:
        constraints:
          - node.role == manager
  cache:
    image: redis:6.0.8-alpine
    healthcheck:
      test: redis-cli ping
    deploy:
      mode: replicated
      update_config:
        order: stop-first
        failure_action: rollback
      placement:
        constraints:
          - node.role == manager
  message_queue:
    image: nats:2.1.9-alpine3.12
    healthcheck:
      test: wget --no-verbose --tries=1 --spider http://localhost:8222/varz || exit 1
    deploy:
      mode: replicated
      update_config:
        order: start-first
        failure_action: rollback
      placement:
        constraints:
          - node.role == manager
networks:
  public:
    external: true

Any Ideas how to solve this issue?


Solution

  • Your server service is in the public network and can‘t see other services. You can fix this by simply adding a private network like:

    networks:
      private:
      public:
        external: true
    

    And use it in other services:

    services:
      server:
        ...
        networks:
        - private
        - public
      cache:
        ...
        networks:
        - private
      ...