3

I have 3 network interfaces: docker0, eth0 and eth0:0 (alias).

    auto eth0
      iface eth0 inet static
      address 1.2.3.4
      netmask 255.255.255.0
      network 1.2.3.0
      broadcast 1.2.3.255
      gateway 1.2.3.254

    auto eth0:0
      iface eth0:0 inet static
      address 5.6.7.8
      netmask 255.255.255.255
      broadcast 5.6.7.8

docker0 is the bridge auto created by docker.

What's the easiest way to make Docker and all its containers use the outbound IP 5.6.7.8 instead of 1.2.3.4?

2 Answers 2

7

It appears there is no easy way to do it with docker - at the moment at least.

What I ended up doing is simply using SNAT:

 iptables -t nat -I POSTROUTING -p all -s 172.17.0.0/16 -j SNAT --to-source 5.6.7.8

172.17.0.0/16 is the subnet used by docker0.

1

Use the --ip command line parameter.

# echo 'DOCKER_OPTS="$DOCKER_OPTS --ip=5.6.7.8"' >> /etc/default/docker
# docker help
...
  --ip=0.0.0.0     Default IP address to use when binding container ports
5
  • Hi, it doesn't work. The public IP used by docker containers is still the same. Apr 29, 2015 at 16:46
  • Does setting the outbound IP for a single container work? Try something like docker run -i -t -p 5.6.7.8:12345:12345 ubuntu /bin/bash
    – cbix
    Apr 29, 2015 at 16:52
  • Outbound IP is still the same. Apr 29, 2015 at 17:04
  • Which docker version are you using?
    – cbix
    Apr 30, 2015 at 5:27
  • I'm using Docker 1.6.0 Apr 30, 2015 at 5:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.