0

I have a solution made by 3 different Java server applications.

The 3 Java applications can run on 3 different physical servers, but also on the same server (depending by number of users, traffic, etc...). They must access a Postgresql database. The database can reside either on a different physical server or on the same physical server as one of the applications.

So there could be a case where the database and the 3 java applications reside on the same physical server, while in another case they reside on 4 different physical servers.

All servers have static IP addresses.

The 3 Java applications are installed through the Docker container, while the PostgreSql DB is installed in the traditional way (without container).

The problem is that the java application sees (by 'getLocalHost()') the address of the container (172.0 ......) as its own address; because it was designed without container, itmust see the physical address of the host (80.211 .....).

Furthermore, when the Java application accesses the database, the database sees that the access request comes from the IP address 172.0... while it should receive it, to allow access, from 80.211 ....

The Java application are runned by a docker file like that:

FROM openjdk:8-oraclelinux8
WORKDIR /mydir
# VOLUME . /
COPY ["./My_name_Java_app.jar", "./My_name_Java_app.properties", "./"]
EXPOSE 80
EXPOSE 8080
EXPOSE 1000-2000
ENTRYPOINT ["/bin/java", "-Djava.awt.headless=true", "-jar", "My_name_Java_app.jar"]

How can I modify the dockerfile so that the host ip address is exposed and not the container address?

Fausto70
  • 541
  • 5
  • 20
  • This seems to be what you're looking for https://stackoverflow.com/questions/22944631/how-to-get-the-ip-address-of-the-docker-host-from-inside-a-docker-container – Arthur Klezovich Nov 03 '21 at 18:02
  • I already saw that post, but to be honest I'm not so expert of Docker and linux, and I didn't understand how to solve the problem. I hope that some expert guy can solve my problem with some few rows to be added to my dockerfile. – Fausto70 Nov 03 '21 at 18:38
  • You can't affect the network environment in the Dockerfile. In the situation you describe, if the database is always on a separate host, I'd expect it to see the IP of the host system making the call and not the container-private IP address. Why does the client IP address matter; can you use something like password authentication instead of an IP ACL? – David Maze Nov 03 '21 at 18:41
  • “I'd expect it to see the IP of the host system making the call and not the container-private IP address”: the problem is that instead the database sees the IP address of the container and not the host, considering however that in this phase of testing the database and container with java app are on the same server, which however can also happen in real life. “Why does the client IP address matter”: It is important because the database accepts only ip address setted in pg_hba.conf file, that are of course the addresse of hosts, and not of containers. – Fausto70 Nov 04 '21 at 08:45

0 Answers0