I am using Grail application and couple of microservices are written which is accessible by grails application. Request comes from grails to Gateway which is on 4000 port. Now based on request gateway will redirect request to respectives services like auth, notification, report, these are the microservices.
Now I am spinning up microservices in docker container, service discovery is on 8761,config server is on 8888, zuul gateway is on 4000 port. Notification service is running on 8755 port and when request comes to Gateway for notification, it redirect first to notification which is working fine for me, as per application flow, notification will validate token hence it will call auth service which is exposed on 8282 port. The moment notification is sending request to auth via gateway its failing ...
everything is working when all services are up and running on 'localhost' this issue is happening when I am starting services in docker container as container will not recognize localhost hence I am changing zuul conifguration as below
zuul:
ignoredServices: '*'
host:
connect-timeout-millis: 120000
socket-timeout-millis: 120000
routes:
notification-service:
path: /notification/**
url: http://${NOTIFICATION_SERVICE_HOST:127.0.0.1}:8755
stripPrefix: true
sensitiveHeaders:
report-service:
path: /report/**
url: http://${REPORT_SERVICE_HOST:127.0.0.1}:8762
stripPrefix: true
sensitiveHeaders:
p2p-auth-service:
path: /authService/**
url: http://${AUTH_SERVICE_HOST:172.17.0.1}:8282
stripPrefix: true
sensitiveHeaders:
When request comes to notification, its coming properly, it mean constant which I added NOTIFICATION_SERVICE_HOST is replaced by the IP which I am passing. But same is not happening when its calling auth service where I have given constant AUTH_SERVICE_HOST. Always it is failing with 500 null message.
my docker compose file is as below
version: '3.7'
services:
configserver:
image: config
container_name: configserver
ports:
- "8888:8888"
networks:
- bridge-abc
environment:
SPRING.PROFILES.ACTIVE: native
EUREKA.CLIENT.SERVICEURL.DEFAULTZONE: http://registry:8761/eureka
registry:
image: registry
container_name: registry
ports:
- "8762:8761"
networks:
- bridge-abc
depends_on:
- configserver
restart: on-failure
environment:
SPRING.PROFILES.ACTIVE: dev
SPRING.CLOUD.CONFIG.URI: http://configserver:8888/
EUREKA.CLIENT.SERVICEURL.DEFAULTZONE: http://registry:8761/eureka
gateway:
image: gateway
container_name: gateway
ports:
- "4000:4000"
networks:
- bridge-abc
depends_on:
- configserver
- registry
restart: on-failure
environment:
SPRING.PROFILES.ACTIVE: dev
SPRING.CLOUD.CONFIG.URI: http://configserver:8888/
EUREKA.CLIENT.SERVICEURL.DEFAULTZONE: http://registry:8761/eureka
REGISTRY_SERVER: registry
REGISTRY_PORT: 8761
NOTIFICATION_SERVICE_HOST: 172.17.0.1
AUTH_SERVICE_HOST: 172.17.0.1
authservice:
image: auth-service
container_name: authservice
ports:
- "8282:8282"
networks:
- bridge-abc
depends_on:
- configserver
- registry
restart: on-failure
environment:
SPRING.PROFILES.ACTIVE: dev
SPRING.CLOUD.CONFIG.URI: http://configserver:8888/
EUREKA.CLIENT.SERVICEURL.DEFAULTZONE: http://registry:8761/eureka
DB_HOST: 1.2.3.4
DB_PORT: 1234
DB_NAME: my-db-name
DB_USERNAME: user
DB_PASSWORD: password
REGISTRY_SERVER: registry
REGISTRY_PORT: 8761
notification:
image: notification-service
container_name: notification
ports:
- 8755:8755
networks:
- bridge-perfios
depends_on:
- configserver
- registry
restart: on-failure
environment:
SPRING.PROFILES.ACTIVE: dev
SPRING.CLOUD.CONFIG.URI: http://configserver:8888/
EUREKA.CLIENT.SERVICEURL.DEFAULTZONE: http://registry:8761/eureka
REGISTRY_SERVER: registry
REGISTRY_PORT: 8761
DB_HOST: 1.2.3.4
DB_PORT: 1234
DB_NAME: my-db-name
DB_USERNAME: user
DB_PASSWORD: password
REGISTRY_SERVER: registry
REGISTRY_PORT: 8761
In above docker compose file I am passing NOTIFICATION_SERVICE_HOST and AUTH_SERVICE_HOST value as 172.17.0.1 so that container can talk to each other, constant AUTH_SERVICE_HOST is not working and always assuming 127.0.0.1 (constant value is not replaced by 172.17.0.1, always it is assuming 127.0.0.1) whereas constant NOTIFICATION_SERVICE_HOST works properly and this constant value is replaced by 172.17.0.1
I am not sure what is wrong here or please suggest if some configuration is missing or I am doing any mistakes.
I have resolved this issue, problem was happening in each microservice where it was validating token, to do this; it will go to gateway and then request will redirect to auth service. While resolving DNS name in each microservice it was mapping with default IP ie 127.0.0.1. I have changed each miceroservice's container /etc/hosts as below
172.17.0.1 'my domain name'
and this resolved my issue.
Now I need to understand how I can make it generic so that if I remove container and run again docker-compose up then below details should auto update to container's host file
172.17.0.1 'my domain name'
Any suggestion is much appreciable.
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.