2

How do I get the Host IP address within an Java application running inside a Docker?

Obviously, if I use the traditional InetAddress.getLocalHost(), it works if the Java program runs directly on the Host. However, if it is running inside a container, then it would not be the physical ip address outside world sees the host.

My use case is that my Java application registers itself as a service provide by inserting into a shared registry (like a database table) with informations like service name, ip address and port number so that others can find and invoke the service.

Someone mentioned the only way is through run --env when you start the container, but how do my Java program gets it? If I have a way to retrieve it from Java, that would work though it looks ugly .....

step-by-step
  • 301
  • 2
  • 4
  • 15

0 Answers0