How to address (IP or hostname) of other container with network_mode : host? (* FIXED *)


Update: I have just fixed this problem also in my github repository. So the references in this post to my github repository no longer show the problem !

I am having a multi container application.
Container 1 (= nodered)is setup with network_mode : host
Container 2 (= nginx) wants to do a redirection of port 80 to port 1880 of container 1.

FYI my OS version = balenaOS 2.29.2+rev1 (development) deployed on a raspberry pi.

All the details of my setup can be found in my balena-node-red-eq3 repository.

The problem is that Container 2 needs to know the IP address or hostname of Container 1 for this redirection. I would have hoped that Container 2 would be able to resolve the name of Container 1 (= nodered) but this doesn’t work as that Container 1 is using network_mode : host

It works when I use the IP address of my device (as it is specified in Balena dashboard). In that case Container 2 can do the redirection to Container 1.
So in my setup I had specified the IP address of my device in my nginx.conf file (see line 27)

I don’t like this solution as it means that my application can not just be deployed on another device as the IP address must first be changed in the nginx.conf file.

So is there a better solution that is not based on the actual IP address of the device ?


I have got it fixed by:

1/ setting also network_mode : host for Container 2 in my docker-compose.yml file
2/ using localhost instead of the IP address in my nginx.conf file (see line 27)