docker / cli

The Docker CLI
Apache License 2.0
4.95k stars 1.93k forks source link

Original ip is not passed to containers [Linux version] #2945

Open Eh1Ka6 opened 3 years ago

Eh1Ka6 commented 3 years ago

-->

Refering to a similar problem seen in docker for-mac I'm using Apache inside an alpine docker-container within kubernetes node replication environnement This container use ProxyPassMatch to serve the php container

Within the php container i try to gather the user's IP with echo $_SERVER["REMOTE_ADDR"]. The ouput shows the IP of the node hosting the container instead of the ip of the end user

Steps to reproduce the issue:

  1. Run any apache container and default php_fpm container on the same node.
  2. Connect both container by adding the config ProxyPassMatch ^/(..php(/.)?)$ fcgi://localhost:9000/
  3. Create a php file on the php container: <?php echo $_SERVER["REMOTE_ADDR"]. ?>

Result will be the adress of the node instead of the client

Additional information you deem important

Output of docker version:

(paste your output here)

Output of docker info:

(paste your output here)

Additional environment details (AWS, VirtualBox, physical, etc.):

thaJeztah commented 3 years ago

For Docker Desktop for Mac I think that's still expected, due to how networking is set up (it's a known issue, but there's quite some complexity involved in docker desktop to make networking "work").

Assuming for the other situation you're running on a Linux machine; does it work if you configure the daemon to not use the userland-proxy? By default, docker uses a proxy to provide hairpin connections; we're planning to change that default (https://github.com/moby/moby/issues/14856), but ran into issues with some "older" distros did not work well without.

You can disable the userland proxy in the daemon configuration (https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file), e.g.

in /etc/docker/daemon.json (assuming you don't have other options set in that file);

{"userland-proxy": false}

After creating, or modifying the /etc/docker/daemon.json, the docker service must be restarted for the change to take effect.

Of course, be sure to try this in a test-environment to verify, before changing your production environment.