1

I am learning how to connect two microservices, first without using a Docker Compose file.

When I include the following IP address eureka.client.serviceUrl.defaultZone=http://172.17.0.2:8761/eureka in the application.properties file and run docker run --name vehicle -p 8080:8080 vehicle -- I manage to connect Eureka and Vehicle Microservices.

BUT if I use the name of the Eureka microservice instead of its address in the application.properties file: eureka.client.serviceUrl.defaultZone=http://discovery:8761/eureka

and run docker run --name vehicle -p 8080:8080 vehicle -- it does not work.

ONLY if I override the env variable like this: docker run --name vehicle -p 8080:8080 -e EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://172.17.0.2:8761/eureka OR if I add a link: docker run --name vehicle -p 8080:8080 --link discovery:discovery vehicle -- it works fine.

My question is why does it work immediately when I include the IP address into the URL in the application.properties file, but I need to use a link or override the URL address if I specify the service name?

My reasoning is that Docker has an embedded DNS system as shown in the picture, thus it should be able to recognize microservices by both their names and addresses. enter image description here

Please help me clarify my understanding.

Kristina Cer
  • 105
  • 9
  • can we see your docker-compose.yml? – Balint May 16 '22 at 15:19
  • Hey @Balint! The whole point of the question is to clarify the basics of two container connection without using Docker compose. Thank you! – Kristina Cer May 16 '22 at 15:23
  • 1
    You also need to `docker network create` a network, and `docker run --net` both containers on that network. (Compose does this automatically for you.) Also see [How to communicate between Docker containers via "hostname"](https://stackoverflow.com/questions/30545023/how-to-communicate-between-docker-containers-via-hostname) for more detailed examples. `docker run --link` is obsolete now and you shouldn't use it. – David Maze May 16 '22 at 15:30

0 Answers0