Score:1

Get real client remote ip in docker-swarm httpd proxy?

eg flag

I'm running a httpd apache2 proxy in docker swarm mode with docker stack deploy.

Problem: when I access mymachine:80, the access.log only shows the remote ip of the docker ingress swarm network, like 10.0.0.2. And not the real clients' ip.

Question: how can I tell swarm to retain the original IP address (maybe write it into another IP header?), without having to force my container or ports into mode: host?

Because I don't want to use zero-downtime deployment, which is what I have in docker-swarm mode without containers in host-mode.

Score:1
ru flag

In short, there's no way to achieve this within the constraints you ask.

Docker swarm uses traffic forwarding, not listening ports, to handle ingress traffic. You can see telltale signs of this with iptables -nL, and noticing that the docker firewall rules (DOCKER-USER, DOCKER-INGRESS, etc) are in the FORWARD chain, not the INPUT chain (and every so often you'll see user caught by surprise, that their ingress firewall rules aren't blocking traffic).

As you pointed out, having your port on mode: host will solve the "real IP" issue (as the listening port will be on the host's "real" network namespace), but that prevents you from doing zero-downtime deployments (because the port is then a single resource in use).

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.