I have run my service with docker swarm, I have two nodes, and I’v run the service with replicas=2.
Here is my docker compose
services:
c2c-mplus-gateway-service:
hostname: c2c-mplus-gateway-service
image: c2c-mplus-gateway-service:1.0
working_dir: /usr/src/myapp
command: bash -c "nohup java -jar /usr/src/myapp/gateway-service-0.0.1-SNAPSHOT.jar"
networks:
- mplus-network
environment:
- TZ=Asia/Bangkok
- _JAVA_OPTIONS=-Xmx512m -Xms256m
- SPRING_PROFILES_ACTIVE=prod, api-docs, no-liquibase
deploy:
replicas: 2
resources:
limits:
memory: 2.5G
ports:
- 8082:8082
networks:
mplus-network:
external: true
I run the service with is command:
docker stack deploy -c docker-compose.yml stack_c2c-mplus-gateway --detach=true
These are networks when I run docker network ls:
NETWORK ID NAME DRIVER SCOPE
21f0a74c5b20 bridge bridge local
652d6041a5a5 docker-registry_default bridge local
2be7df7c024d docker_gwbridge bridge local
d3444c9e3eec host host local
ia5xtksz2i2e ingress overlay swarm
9crf4h745f63 mplus-network overlay swarm
When I call to my service on port 8082, it always has this log:
stack_c2c-mplus-gateway_c2c-mplus-gateway.1.jkdt2iu1le53@app1.localdomain | io.netty.channel.ConnectTimeoutException: connection timed out: /10.0.0.137:8082
stack_c2c-mplus-gateway_c2c-mplus-gateway.1.jkdt2iu1le53@app1.localdomain | at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe$2.run(AbstractEpollChannel.java:613)
stack_c2c-mplus-gateway_c2c-mplus-gateway.1.jkdt2iu1le53@app1.localdomain | Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
stack_c2c-mplus-gateway_c2c-mplus-gateway.1.jkdt2iu1le53@app1.localdomain | Error has been observed at the following site(s):
When I check the network, I realized that the ip 10.0.0.137 is from ingress network (here the information of a container network of 1 replica when I run docker inspect container_id):
"Networks": {
"ingress": {
"IPAMConfig": {
"IPv4Address": "10.0.0.137"
},
"Links": null,
"Aliases": null,
"MacAddress": "02:42:0a:00:00:89",
"NetworkID": "ia5xtksz2i2eyr36vsbir6g3t",
"EndpointID": "da08fd84018bd2b85ce86b3f1af4a62b916187ea4401533072fae446ab92ac5d",
"Gateway": "",
"IPAddress": "10.0.0.137",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"DriverOpts": null,
"DNSNames": [
"stack_c2c-mplus-gateway_c2c-mplus-gateway.2.6sywh2m6wttrut40vhyz63ixu",
"eac16bee7e81",
"c2c-mplus-gateway"
]
},
"mplus-network": {
"IPAMConfig": {
"IPv4Address": "10.0.82.5"
},
"Links": null,
"Aliases": null,
"MacAddress": "02:42:0a:00:52:05",
"NetworkID": "9crf4h745f63mge3csifd1w81",
"EndpointID": "0353fa0de3573d1201c3280c2890694245c7715bf653f2aaa3ad28b65cd0eefd",
"Gateway": "",
"IPAddress": "10.0.82.5",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"DriverOpts": null,
"DNSNames": [
"stack_c2c-mplus-gateway_c2c-mplus-gateway.2.6sywh2m6wttrut40vhyz63ixu",
"eac16bee7e81",
"c2c-mplus-gateway"
]
}
}
}
How to address this problem? it’s taken me a lot of time dealing with this problem, but I can’t find a solution.