Hi,
I am trying to deploy a microservices architectures on ec2 aws instances with docker swarm. I have 5 ec2 instances, 4 workers and 1 manager. That part works perfectly all the workers connect to the manager without any issue.
I am using the docker-compose.yml file below to deploy my stack. It contains 4 service and 3 of them depend on one service so I need to communicate between them. So I setup an overlay network to be able to communicate between themself with docker swarm on different host. I am using the dns tasks.<service-name>
fomart to perform it as specify in the docker swarm documentation.
It start all the service but then as 3 out of 4 service can’t access to the service they depend on with the dns name so they crashed and are stopped.
I don’t understand why I can’t communicate between my service from different host with the overlay network and dns name. What I am doing wrong and how can I fix it to make it work ?
PS: all the ec2 instances are on the same subnet and I can communicate between the private ipv4 of each instances on the host and inside a container but not with the 10.xx.xx.xx adress ip or with the dns.
PS 2 : I have a security group (that replace firewall with ec2 instances on aws) where I allow inbound connection
on tcp for the ports : 2377,4789,7946 and the port 7946 for udp protocole. as outbound connection I allow all the protocol on every port and every ipv4 adress
version: '3.9'
services:
test:
container_name: test-service
image: thomaslpro/test-service
depends_on:
- registration
command: sh -c "/wait && java -server -XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport -jar test.jar"
deploy:
placement:
constraints:
- node.role == worker
ports:
- 8081:8081
environment:
- SPRING_PROFILES_ACTIVE=prod
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://tasks.my_app_registration:8761/eureka
- WAIT_HOSTS=tasks.my_app_registration:9999
- WAIT_HOSTS_TIMEOUT=300
- WAIT_SLEEP_INTERVAL=30
- WAIT_HOST_CONNECT_TIMEOUT=30
networks:
- app-network
configuration:
container_name: config-service
image: thomaslpro/config-service
deploy:
placement:
constraints:
- node.role == worker
ports:
- 8888:8888
environment:
- SPRING_PROFILES_ACTIVE=prod
networks:
- app-network
gateway:
container_name: gateway
image: thomaslpro/gateway-service
depends_on:
- registration
command: sh -c "/wait && java -server -XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport -jar gateway.jar"
deploy:
placement:
constraints:
- node.role == worker
ports:
- 9999:9999
environment:
- SPRING_PROFILES_ACTIVE=prod
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://tasks.my_app_registration:8761/eureka
- WAIT_HOSTS=tasks.my_app_registration:9999
- WAIT_HOSTS_TIMEOUT=300
- WAIT_SLEEP_INTERVAL=30
- WAIT_HOST_CONNECT_TIMEOUT=30
networks:
- app-network
registration:
container_name: registration
image: thomaslpro/registration-service
depends_on:
- configuration
command: sh -c "/wait && java -server -XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport -jar registration.jar"
deploy:
placement:
constraints:
- node.role == worker
ports:
- 8761:8761
environment:
- SPRING_PROFILES_ACTIVE=prod
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://tasks.my_app_registration:8761/eureka
- WAIT_HOSTS=tasks.my_app_configuration:8888
- WAIT_HOSTS_TIMEOUT=300
- WAIT_SLEEP_INTERVAL=30
- WAIT_HOST_CONNECT_TIMEOUT=30
networks:
- app-network
networks:
app-network:
name: app-network
driver: overlay
internal: true
attachable: true