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