I have a Docker host that should allow each container to have multiple static IP addresses. The application inside the container should then be able to choose from which address it will send traffic to remote hosts (e.g. ping -I <source-address> example.com
).
Imagine a setup like this: IP addresses 10.0.0.10 - 10.0.0.19
are assigned to ContainerA, 10.0.0.20 - 10.0.0.29
to ContainerB and so on. Any traffic to ContainerA's address range is forwarded to ContainerA, while outgoing traffic originates from an address from that range that ContainerA can chose. The same applies to ContainerB.
The default --net=bridge
mode does not seem to support this. The closest I could get is that incoming traffic to any of ContainerA's addresses is correctly forwarded to the container, but outgoing traffic always originates from the same single address.
When using --net=host
, the first container will attach to all available IP addresses, thus the second container will not be able to open the sockets in its IP range.
The --ip
option of the docker run
command seems to come close to what I need, as explained in this blog post. Unfortunately, it does not seem to support multiple static IPs per container.
If more convenient, using CIDR subnets instead of IP ranges is fine.
How do I need to configure Docker to achieve this?