3

I am trying out a simple service discovery scenario using different docker stacks.
Let's assume I am having 2 stacks. For simplicity purpose,I am naming them as stackA and stackB. StackA has a service called 'serviceA' and StackB has a service called 'serviceB'. ServiceA and serviceB are having a simple RestApplication.

Now I want to call serviceB from serviceA. I understand the concept of docker service discovery and followed the docker official document but unable to call serviceB. discovering-services-or-containers-on-another-stack

As per official doc, I am using serviceB.StackB , but couldn't do.

Unable to understand the reason.Few points:
1.each stack creates its own network. Is it happening because both stacks are not in same network?
2. What if I need them in the different network only, how do I call different services

Vivek Shukla
  • 711
  • 9
  • 18
  • Are you using docker cloud? Or running on your server? – leodotcloud May 18 '18 at 04:54
  • You tagged your question with "resttemplate" so I assume you're using Spring Boot? If so, have a look at "Eureka", it is the best practice for discover microservices with Spring. These microservices can be put into their own docker container and will speak to each other autmatically. – Bennett Dams May 18 '18 at 11:08
  • @leodotcloud I am not using docker cloud. Its having 3 nodes, 1 manager, and 2 workers – Vivek Shukla May 18 '18 at 14:07
  • @BennettDams Yes, I am using Spring-Boot. However, I am not using Netflix OSS. If I use netflix, I would have gone with feign client. – Vivek Shukla May 18 '18 at 14:07
  • @VivekShukla Based on the documentation link you provided, I think service.stack resolution could be a feature of Docker cloud, not for custom setups? But I haven't tried myself though. – leodotcloud May 18 '18 at 18:16
  • @leodotcloud I have already mentioned service.stack in my question which is not working. – Vivek Shukla May 19 '18 at 05:48

1 Answers1

5

I have found the solution to above problem.
You need to follow 2 steps:

  1. The services which want to communicate with each other should belong to same network
version: "3"
  services:
    serviceA:
    ....
    networks:
    - YOUR_NETWORK
networks:
  YOUR_NETWORK:
    external: true

2. If you deploy your stack, your service is always prefixed with stack name such as **STACK-NAME_SERVICE-NAME**.
for discovering another service, just use STACK-NAME_SERVICE-NAME:PORT
Chen A.
  • 10,140
  • 3
  • 42
  • 61
Vivek Shukla
  • 711
  • 9
  • 18