I have a host with multiple external IP addresses and I’m running docker with a scalable service. My end goal is to be able to bind to a specific IP address of the host from with in the container. For example I’d like to execute
curl http://ifconfig.co --interface ethN where
N is the Nth interface in the container bound to the Nth IP address of the docker host.
Is this possible with a docker service?
The container doesn’t know anything about the host’s networking. You specify this sort of thing when you set up published ports in your
docker run command.
Say you have a container running a management-oriented Web server. Your host has a “public” IP address 10.20.0.3/16, and a “private” IP address 192.168.144.3/24. You want to publish the service on port 8888 only on the private network. You might run:
docker run -d -p 192.168.144.3:8888:80 myimage \
start_server.sh --bind 0.0.0.0:80
where the second line is a made-up command line to start the daemon.
The container doesn’t know anything about the host’s networking.
@dmaze are you saying its impossible?
Maybe I should have been more specific. I think what I really need is IP masquerading but for the IP that I choose,
1 approach could be modifying the iptables on the host to choose the source ip address that you need. This is not a clean approach…