0

i am running redis and a nodejs application each one in its own container and i have connection issues between my nodejs application and the redis db.

so i am running a docker stack on my swarm and it has multiple services that connect to redis, all of the other services that connect to redis work fine. and they use the same code to create the connection to redis as the problematic service.

what i have found out is: i am able to go into the container with docker exec -it <container-id> /bin/sh and ping and redis container's hostname and it works fine. i get this error:

UnhandledPromiseRejectionWarning: Error: getaddrinfo ENOTFOUND redis

ALSO: when i go into the container and run the code MANUALLY by doing node index.js it manages to connect to the redis with no issue.

my docker-compose file has also a depends_on section so the container with the connection issues depends on the redis container

i am using bull to connect to my redis instance. node:8-alpine image for each of my services.

version: "3.7"
services:
  redis:
    image: redis:alpine
    command: redis-server --requirepass SECRETPASSWORD123
    ports:
      - 6379:6379

  service1:
    build:
      dockerfile: src/services/<service>/Dockerfile
      context: ./
      target: prod
    image: 
    deploy:
      restart_policy:
        condition: on-failure
    dns: 8.8.8.8
    env_file:
      - ./.env
    working_dir: /app/
    volumes:
      - ./src:/usr/app/src:cached

  service2:
    build:
      dockerfile: src/services/<service>/Dockerfile
      context: ./
      target: prod
    image: 
    deploy:
      restart_policy:
        condition: on-failure
    dns: 8.8.8.8
    env_file:
      - ./.env
    working_dir: /app/
    volumes:
      - ./src:/usr/app/src:cached

  service3:
    build:
      dockerfile: src/services/<service>/Dockerfile
      context: ./
      target: prod
    image: 
    deploy:
      restart_policy:
        condition: on-failure
    dns: 8.8.8.8
    env_file:
      - ./.env
    working_dir: /app/
    volumes:
      - ./src:/usr/app/src:cached

  service:
    build:
      dockerfile: src/services/<service>/Dockerfile
      context: ./
      target: prod
    image: 
    deploy:
      restart_policy:
        condition: on-failure
    dns: 8.8.8.8
    env_file:
      - ./.env
    depends_on:
      - redis

  service11:
    build:
      dockerfile: src/services/<service>/Dockerfile
      context: ./
      target: prod
    image: 
    deploy:
      restart_policy:
        condition: on-failure
    dns: 8.8.8.8
    depends_on:
      - redis
    env_file:
      - ./.env

  service22:
    build:
      dockerfile: src/services/<service>/Dockerfile
      context: ./
      target: prod
    image: 
    deploy:
      restart_policy:
        condition: on-failure
    dns: 8.8.8.8
    depends_on:
      - redis
    env_file:
      - ./.env

  service31:
    build:
      dockerfile: src/services/<service>/Dockerfile
      context: ./
      target: prod
    image: 
    deploy:
      restart_policy:
        condition: on-failure
    depends_on:
      - redis
    dns: 8.8.8.8
    env_file:
      - ./.env
    ports:
      - 8080:8080

  wm-backup:
    build:
      dockerfile: src/services/<service>/Dockerfile
      context: ./
      target: prod
    image: 
    deploy:
      resources:
        reservations:
          cpus: '0.5'
          memory: 4g
      restart_policy:
        condition: on-failure
    dns: 8.8.8.8
    env_file:
      - ./.env

  zibi2:
    build:
      dockerfile: src/services/<service>/Dockerfile
      context: ./
      target: prod
    image: 
    deploy:
      restart_policy:
        condition: on-failure
    env_file:
      - ./.env
    working_dir: /app/
    dns: 8.8.8.8
    volumes:
      - ./src:/usr/app/src:cached

  service415:
    build:
      dockerfile: src/services/<service>/Dockerfile
      context: ./
      target: prod
    image: 
    deploy:
      restart_policy:
        condition: on-failure
    env_file:
      - ./.env
    working_dir: /app/
    dns: 8.8.8.8
    volumes:
      - ./src:/usr/app/src:cached

  zubi31312:
    build:
      dockerfile: src/services/<service>/Dockerfile
      context: ./
      target: prod
    image: 
    deploy:
      restart_policy:
        condition: on-failure
    env_file:
      - ./.env
    working_dir: /app/
    dns: 8.8.8.8
    volumes:
      - ./src:/usr/app/src:cached

sample of the docker-compose file. images are private so i didn't put those in

when i run the stack locally on my server everything seems to work fine, but as soon as it runs through jenkins it gets this issue

Eitank
  • 570
  • 8
  • 21
  • 1
    How would someone reproduce this issue? Can you add artifacts like your `docker-compose.yml` file to the question? – David Maze Dec 29 '19 at 12:52
  • @DavidMaze added my compose file – Eitank Dec 29 '19 at 13:18
  • There seem to be 11 different services there. Which one is having the problem? Aside from working correctly, are any relevant to the situation? You mention Swarm; is there one node or multiple? You have bind mounts that completely replace the code in the container; are you destroying critical parts of your application build this way, and is the same code on every node? – David Maze Dec 29 '19 at 14:41
  • @DavidMaze i tried using the depends_on flag and it is NOT supported in docker swarm. but i found a solution in this thread: https://stackoverflow.com/questions/49283363/docker-swarm-list-dependencies-of-a-service and it fixes the issue – Eitank Dec 29 '19 at 15:00

0 Answers0