-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Unable to choose outbound (external) IP for containers #30053
Comments
/cc @sanimej ptal |
@mitar For external connectivity docker programs a One work around I can suggest is..
|
OK, but marking would be based on e-mail traffic port, not on the container. There is no way currently to ask Docker to mark all traffic from a container with some mark? |
Yes, this custom marking is something you have to do yourself. |
Is there a way to make the container's internal IP static? Or a preferred way to run a command on the host each time the container starts? If yes, then some simple Another idea is to mark traffic with |
The |
Oh, I hoped we could get rid of dynamic configuration of the network stack now that there is support for Docker networks. We made this daemon in the past to configure custom network configuration so that we could use custom routing inside Docker. But with Docker networks this is more or less obsolete. The only open case is this outbound/external IP. I think it would be great if this could be something supported by Docker directly. |
If someone can write a proposal for this functionality, including what the UX would look like, it could be looked into to see if there's a way to implement. |
I think it could be as simple as adding two more options to Docker the
Behavior would be similar to how for normal programs you can "bind" a program to an IP to use that IP for outgoing packets. Simply, all outgoing traffic would go through that IP out. Some other names I was considering: I think this would cover the most cases when one needs this. But I would also consider adding another option: I am not sure if marks for iptables is considered breaking a Docker abstraction. For me, the simple argument above would be enough. |
I have the same problem, docker network create NETWORK --subnet=192.168.1.0/24 --gateway=192.168.1.1 # choose an unused subnet
iptables -t nat -I POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source OUTGOING_IP # remember that Docker also edit POSTROUTING
docker network connect NETWORK CONTAINER # or with Compose |
@viossat: But if I want that CONTAINER is one other network, so that other containers can talk to it? I can attach it to two networks, but how do I know which one will it use to communicate out? |
I agree to |
Has there been any new thoughts or progress on this issue? Do you think we need to raise this issue on the official Docker tracker or is this sufficient? Really want there to be an elegant solution to this as well; I also concur that --outgoing-ip would be a great solution. +1 |
@viossat I am trying to assign a container using eth1. |
@y2kbug-hk Have you assigned a fixed custom |
@viossat I have no idea what value to specify, so I inspect the value after creation. It gives Hence
|
I made a docker image which configures the external IP of any container having |
In swarm mode we can prepare a network with driver bridge and scope swarm. |
@FalkNisius could you open a separate ticket for that with details? Not sure if that was "by design" or "for future implementation" (and don't want to derail the discussion here 😄) |
what is the right github project ? this one, the network subsystem, the bridge driver ? |
This project / repository is fine |
Run in the same issue. I have multiple ipv4 and ipv6 ip's attached to eth0 and want to use these on container basis in swarm mode w/ compose. |
full diff: moby/libnetwork@feeff4f...6659f7f includes: - moby/libnetwork#2317 Allow bridge net driver to skip IPv4 configuration of bridge interface - adds support for a `com.docker.network.bridge.inhibit_ipv4` label/configuration - addresses moby#37430 Prevent bridge network driver from setting IPv4 address on bridge interface - moby/libnetwork#2454 Support for com.docker.network.host_ipv4 driver label - addresses moby#30053 Unable to choose outbound (external) IP for containers - moby/libnetwork#2491 Improving load balancer performance - addresses moby#35082 [SWARM] Very poor performance for ingress network with lots of parallel requests Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
fixed on master through #40579 |
I think this is related as well: moby/libnetwork#2454 |
yes that's the change that's being vendored through #40579 |
This configuration worked for me, using @mitar image: I have one NIC (eth0) with two sub-interfaces (eth0:1 and eth0:2). I used private IPs which are NATed upstream by my netowrk router. But I guess this should work with public IPs too.
My docker-compose.yml file
You can test it using I hope this helps someone out there. |
Thank you @tikoflano this helped a lot! Had to convert |
Feel free to make MR to the repo with alpine and stuff if you want. |
Hi, I just stumbled across this issue, its the closest thing I've found so far so please could you help me :) Was this ever done? I have bought a public/ripe /28 subnet from my hosting provider, I have managed to route the IPs to each container and I can connect to them individually using their public IP, however, their external IP when I curl some site like "what's my ip address" shows up as the host/dedicated server's ip instead of the containers ip. Do you know what I need to do in order to have my containers show up as their own IP? Thanks :) |
@MrBenFTW A label has been added to docker networks, which you can use: moby/libnetwork#2454 for reference. |
Thanks! Just to clarify, do I need to make a new network for every container or can IE, can I create a docker bridge subnet with my 123.123.123.123/28 ip and then on each container do com.docker.network.host_ipv4 = 123.123.123.124 and so on |
The label only exists on a network. So you would need to create one network per public ip address. |
I think something like this would be better
and then
when |
I can't get this solution to actually work anyways, my host requires that the IPs are statically routed through the main ip of the server, because of this, the gateway must be the first ip in the subnet. But if i have to create a new network for each ip in a subnet I don't see how I can do so without each one being in a /32 subnet, and in this case the gateway ip is not accessible as it is outside of the subnet.. |
Hello @itouch5000 :) I used the same approach as you to be able to bind a physical NIC to one docker network and so far it works really well. My issue now is that using the same kind of routes as yourself, if I attach 2 containers on this bridge-coi network with IP 172.18.0.3 and 172.18.0.4 somehow they can't communicate anymore. It seems logical as all the traffic is routed to the external NIC. I am not the best in terms of routing and iptables but any ideas how to proceed so that container in the bridge-coi network can still continue to reach each other and for all outbound traffic to use the interface the bridge is linked to ? |
This commit allows a user to specify a Host IP via the com.docker.network.host_ipv4 label which is used as the Source IP during SNAT for bridge networks . The use case is for hosts with multiple interfaces and this label can dictate which IP will be used as Source IP for North-South traffic In the absence of this label, MASQUERADE is used which picks the Source IP based on Next Hop from the Route Table Addresses: moby#30053 Signed-off-by: Arko Dasgupta <arko.dasgupta@docker.com>
Can vouch this works perfectly (Ubuntu VM running inside ProxMox) |
is it possible to add similar option |
I opened #46469 to request IPv6 support. |
In single host mode (no swarm and more complicated stuff) I have a host with multiple public IPs. It seems there is no way to configure which of those IPs containers use for outbound communication. Always the primary IP on the host is used. So I would need that different containers are seen on the Internet as using different IPs.
My use case is a mail server. I have an extra IP allocated to the server to use for sending e-mails so that forward and backwards DNS entries can match. The other IP address is used for HTTP virtual hosting and has many different DNS entries. Additionally using an extra IP for a dedicated mail server is in general a good practice.
Tried with Docker 1.12.5 on Linux (Ubuntu 16.04.1 LTS) with 4.8.0 kernel.
The text was updated successfully, but these errors were encountered: