How to get a true remote IP behind caddy reverse proxy

None of this is useful in your case. You can remove all this.

Your problem is that Docker sometimes uses a userland-proxy, i.e. acts as a TCP-layer proxy in front of Caddy, which means the source IP is lost.

This isn’t a Caddy problem, but rather a Docker problem. This is a long-standing issue with Docker, for example Document how to get real remote client ip for service running in container · Issue #15086 · moby/moby · GitHub