Docker Community Forums

Share and learn in the Docker community.

Identify container endpoint based on service name


I’m trying to get a service to find another service as follows:

  • first service will have a container that executes a java image (SpringBoot) that exposes an endpoint (http: // …: 80).
  • second service will have another container that executes another java image (SpringBoot) that needs to consume the endpoint of the first container.

The problem is that every time I restart the service it will throw the container away and create a new container.

It is possible to identify which endpoint the service is responding to based on the service name (whereas the service name never changes, only the container changes).

Thank you all!

A conntainer has no knowledge about it’s ouside world.

Though, if you create a custom network (docker network create or within a docker-compose.yml), you can use the service names to resolve other containers in the same network.

Please share how you start your two containers (preferebly with a docker-compose.yml) and someone should be able to tell how it needs to be used to achive your objective.