[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Original ip is not passed to containers #180

Closed
withinboredom opened this issue Aug 8, 2016 · 94 comments
Closed

Original ip is not passed to containers #180

withinboredom opened this issue Aug 8, 2016 · 94 comments

Comments

@withinboredom
Copy link

Expected behavior

See my real ip (or an X-FORWARDED-FOR header): ex: 10.100.2.14

Actual behavior

Instead I see 172.19.0.1, which is not my host's ip.

Information

Diagnostic ID: 70CE1D3C-D5A6-4C95-ABA8-17CEF9371D01
Docker for Mac: 1.12.0 (Build 10871)
macOS: Version 10.11.6 (Build 15G31)
[OK] docker-cli
[OK] app
[OK] moby-syslog
[OK] disk
[OK] virtualization
[OK] system
[OK] menubar
[OK] osxfs
[OK] db
[OK] slirp
[OK] moby-console
[OK] logs
[OK] vmnetd
[OK] env
[OK] moby
[OK] driver.amd64-linux

Steps to reproduce the behavior

  1. HOST: docker run --rm --name nginx-test -p 8080:80 nginx
  2. HOST: curl localhost:8080
  3. You'll see an ip in the logs with something like 172.17.0.1, take note of that.

This is not the ip address of the actual machine that made the call. For debuggers that call back to the originating ip (such as php xdebug) this means docker cannot be used to debug anything. I would expect to see an IP of the original machine (such as a truly remote host).

@AlexGustafsson
Copy link

Isn't that expected behavior? Since you're not passing any network flag the container is using the default bridge mode. So you're seeing the container's IP address on the docker0 bridged interface.

@withinboredom
Copy link
Author
withinboredom commented Aug 9, 2016

No, I should see the remote ip (like in linux or docker toolbox) of the connected machine from inside the container, and not the container's gateway ip.

@withinboredom
Copy link
Author

This is a pretty serious issue as NAT appears to be broken ... kind of a deal breaker.

@samoht
Copy link
Contributor
samoht commented Oct 11, 2016

I confirm that I can reproduce the issue. I will discuss the issue further with the team to see what we can do to fix it.

@samoht
Copy link
Contributor
samoht commented Oct 11, 2016

I also confirm that we can reproduce the issue on Linux, so the issue is not in Docker for Mac. /cc @thaJeztah is it a know issue on Linux?

@samoht samoht closed this as completed Oct 11, 2016
@ijc
Copy link
Contributor
ijc commented Oct 11, 2016

I had second thoughts about whether I had really reproduced on native Linux.

I had done a docker run then a ⁠⁠⁠⁠curl localhost...⁠⁠⁠⁠ like the ticket says and saw an originating IP of 172.17.0.1, which is the IP of the ⁠⁠⁠⁠docker0⁠⁠⁠⁠ bridge, which thinking about it more is an IP of the originating host (even if one maybe wouldn't think about it as "the" IP of the host).

In the for-mac case the ⁠⁠⁠⁠172.17.0.1⁠⁠⁠⁠ is not going to be an address which the OSX host knows about, which is the crux of the issue here since something which ought to dial back to the mac will end up dailing back to the VM hosting the containers instead.

So I think I was too quick to tell @samoht I was seeing the same issue on native Linux, sorry. Reopening.

I think what would be needed here would be some mechanism to forward ports back out of the VM to the host (i.e. the inverse of what docker run -p NN:NN does). ISTR that being discussed in another context somewhere but the specifics are escaping me right now.

@ijc ijc reopened this Oct 11, 2016
@thaJeztah
Copy link
Member

@samoht @ijc25 I know there's an issue in swarm mode (see moby/moby#25526)

@PanJ
Copy link
PanJ commented Oct 11, 2016

I tried to replicate the issue and found out that the IP address like 172.17.0.1 only appears when the request is originated from the same host as the container.

This behavior is for standalone container. For swarm mode, it is another separate issue.

@thaJeztah
Copy link
Member

@PanJ in that case, I suspect it's because of the userland-proxy

@PanJ
Copy link
PanJ commented Oct 11, 2016

@thaJeztah
I just noticed that this is docker for mac repo. Tried to reproduce again with docker for mac and the problem persists event the client and server is different machine. Both with machine in same network and doing NAT over the internet.

@samoht
Copy link
Contributor
samoht commented Jan 31, 2017

Thanks for the report and sorry the delay! I have forwarded the issue to our networking team, we will keep you updated when we start making progress on fixing that issue.

@djs55
Copy link
Contributor
djs55 commented May 4, 2017

I think making this just work in Docker for Mac will be quite involved. We can't add an X-Forwarded-For header since this is a TCP proxy, not an HTTP one. I think we would have to teach the userland proxy how to do transparent proxying i.e. to spoof the client IP. From a quick glance at https://www.haproxy.com/blog/howto-transparent-proxying-and-binding-with-haproxy-and-aloha-load-balancer/ I think this involves some or all of:

  • CONFIG_NETFILTER_{,XT_TARGET_}TPROXY kernel options
  • net.ipv4.ip_nonlocal_bind
  • some new iptables rules: would need to be careful here to avoid damaging the main docker/swarm ones
  • some new routing
  • update the tunnelling protocol to pass in the client IP and use it inside the VM

As a workaround in the meantime perhaps you could run an explicit HTTP proxy container yourself, and make it add the X-Forwarded-For header?

@withinboredom
Copy link
Author

@djs55 for what it's worth, this also appears to happen with Docker Swarm mode ...

moby/moby#25526

@mrmachine
Copy link

This makes it impossible to test things like HAproxy load balancing via source method which checks the IP address of incoming requests when determining which container to send a connection to on Docker for Mac. All incoming requests will appear to originate from the same IP, the HyperKit VM's IP (not the macOS host IP or other LAN IP).

@runeimp
Copy link
runeimp commented Nov 17, 2017

@samoht Just checking on the status of this. The issue is over a year old and doesn't sound like it's being actively reviewed in the last 9 months. Can we get a status update? Please.

@farazpartoei
Copy link

this configuration worked for me

ports: - mode: host protocol: tcp published: 8082 target: 80

changing port bind mode to host

how ever you should force your fronted container to run on the specific host in swarm cluster only

i.e.
deploy: placement: constraints: [node.role == manager]

@cryptax
Copy link
cryptax commented Apr 3, 2020

this works for me:

version: "3.2"
services:
   mycontainer:
     build:
       context: .
     ports:
        - "2221:2221"
        - "30000-30009:30000-30009"
     container_name: mycontainer
     network_mode: host

Note the addition of network_mode: host. I didn't need to use lines such as ports: - mode: host protocol: tcp published: 8082 target: 80.
And now my container sees the original IP address of incoming sockets.

@dvcrn
Copy link
dvcrn commented Apr 10, 2020

As this is the docker for mac repository: https://docs.docker.com/network/network-tutorial-host/

The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.

@roenw
Copy link
roenw commented Apr 17, 2020

I'm not sure if this helps, but I am experiencing this issue on CentOS 8 with DockerCE.
But when I run sudo firewall-cmd --permanent --zone=trusted --remove-masquerade I am able to read incoming IPs from within the container. If Mac supports iptables I would look into that.

@sorgloomer
Copy link

Those solutions above only work on Linux.

The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.

I wanted to run Tomcat Docker on a Windows host, only to find out that I cannot access the management interface. By default, it is only accessible from localhost as a security measure. So my only option afaik is to reconfigure Tomcat and compromise my apps security.

@abelmferreira
Copy link

Same here
Docker Desktop 2.2.0.5
Docker Engine 19.03.8

On Mac OSX 10.14.6
$ docker run -it --rm -p 80:80 --name whoami containous/whoami

On a remote machine
$ curl 192.168.25.87
Hostname: 07a90be6f0fa
IP: 127.0.0.1
IP: 172.17.0.2
RemoteAddr: 172.17.0.1:46448
GET / HTTP/1.1
Host: 192.168.25.87
User-Agent: curl/7.54.0
Accept: /

Expected to be the ip from remote client on 192.168.25.0 network

@logopk
Copy link
logopk commented Jun 26, 2020

As a reply to my crosspost to boot2docker I‘ve got the hint to put this problem/wish on the roadmap at https://github.com/docker/roadmap
Apparently the issue is internally known, but that may get this more publicity...

@renatoaraujoc
Copy link

So, we're in August, can't we have a solution from docker team? I just want to have the original ip forwarded to containers :/

@skududufru
Copy link

Same for me. Can we have the original IP forwarded? 😁 🙏

@shafzhr
Copy link
shafzhr commented Aug 17, 2020

this works for me:

version: "3.2"
services:
   mycontainer:
     build:
       context: .
     ports:
        - "2221:2221"
        - "30000-30009:30000-30009"
     container_name: mycontainer
     network_mode: host

Note the addition of network_mode: host. I didn't need to use lines such as ports: - mode: host protocol: tcp published: 8082 target: 80.
And now my container sees the original IP address of incoming sockets.

Thanks. Worked for me.

@tbessenreither
Copy link
tbessenreither commented Aug 17, 2020

Yeah we know that. But host mode only circumvents the problem.
host mode is not usable in swarm / service environments where mutliple instances need to run on the same machine.
PS:
Happy 4th birthday for a issue that should be fixed like... 4 years ago.

@correiajoao
Copy link

Same for me...

@devgnx
Copy link
devgnx commented Oct 14, 2020

Yep, same here on Linux aswell

@knigitz
Copy link
knigitz commented Oct 14, 2020

Still an issue in Docker Desktop in Windows 10. This prevents setting up ACL in web based applications hosted inside a Docker container. This should be marked critical and have a proper fix.

@ghost
Copy link
ghost commented Oct 14, 2020

This issue has prevented me from using my applications in production. Is this in the "Roadmap" anywhere?

@stephen-turner
Copy link
Contributor

This feature request has now moved to docker/roadmap#157, so I'm going to close this ticket.

@Trackhe
Copy link
Trackhe commented Nov 8, 2020

I'm not sure if this helps, but I am experiencing this issue on CentOS 8 with DockerCE.
But when I run sudo firewall-cmd --permanent --zone=trusted --remove-masquerade I am able to read incoming IPs from within the container. If Mac supports iptables I would look into that.

It helps but the performance is going so bad from 19ms to 2-3seconds
On Linux

@sharkymcdongles
Copy link

I'm not sure if this helps, but I am experiencing this issue on CentOS 8 with DockerCE.
But when I run sudo firewall-cmd --permanent --zone=trusted --remove-masquerade I am able to read incoming IPs from within the container. If Mac supports iptables I would look into that.

It helps but the performance is going so bad from 19ms to 2-3seconds
On Linux

This worked for me and performance wasn't degraded at all.

@docker-robott
Copy link
Collaborator

Closed issues are locked after 30 days of inactivity.
This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle locked

@docker docker locked and limited conversation to collaborators Dec 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests