How to get real IP behind two cascaded Nginx?

What I’m trying to do:
I’ve setup one Nginx to act as a reverseproxy and to terminate https and forward the traffic by it’s incomming domain to several other webservices, also running as Nginx. All in an Docker environment.

((Internet)) == :80/:443 ==> [nginx-proxy] == :80 ==> [service_a]

In most of my services i need to know the IP of the caller from the Internet. Therefore i’ve added:

proxy_set_header X-Real-IP $remote_addr;

in the reverseproxy.

I’m using Docker 28.0.1 and Nginx 1.27.4 (all Containers)

Where I’m stuck:
Sometimes i can see the real IP arriving at my services and sometimes i get 172.18.0.1 instead.

What I’ve already tried:
I sometimes read that people where using the “host” network mode instead of “bridge”, but for me this is no option because a ran a lot of services using the same inbound-port and this only works in bridge (i think).

Looking at the reverseproxy Container network config if find this:

                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.6",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,

So 172.18.0.1 is the gateway address of the bridge-network, which seem to not have a IPv6 address?