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.
Please help me clarify my understanding.