Conn.remote_ip uses Docker container gateway IP address rather than actual source IP address (container has been deployed in a Swarm)

Hi everyone! this is my first question on here so please forgive me if I format my inquiry poorly.

When I run my docker container locally, I request conn.remote_ip for the origin IP address of the request, it works correctly and returns ::ffff: - which matches the IP address of the machine on the same LAN that makes the request.

When I have the docker container running in a swarm, every conn.remote_ip that it intercepts is ::ffff: which appears to be the gateway IP address of the container, rather than the true origin IP address (the machine that made the request).

Does anyone know if this is typical behavior when using conn.remote_ip within a docker swarm? and can anyone point me in the right direction for resolving this?

This is expected behaviour when a request is forwarded. If you want to resolve to the original IP you’ll need to look into packages like

1 Like