Static IP not working

My ISP has given me a 10 IP addresses. x.x.x.91-95 and x.x.x.161-165
I want to use 9 of them for my containers.

I have the host eth0 on x.x.x.91

So I did:
docker network create --subnet x.x.x.0/24 --gateway x.x.x.254 mynet

and then

docker run -it --net mynet --ip x.x.x.165 ubuntu /bin/bash

But I can’t connect out. Inside a container:

PING ( 56 data bytes
3 packets transmitted, 0 packets received, 100% packet loss

# ifconfig 
eth0      Link encap:Ethernet  HWaddr 02:42:5b:cc:d2:a5  
          inet addr:x.x.x.165  Bcast:  Mask:
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1296 (1.2 KB)  TX bytes:504 (504.0 B)

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         x.x.x.254         UG    0      0        0 eth0
x.x.x.0   U     0      0        0 eth0

Any ideas?
Docker version 17.09.0-ce, build afdb6d4

It seems to be a problem with the IP address that is assigned to the bridge docker creates.

br-99d73cc121b0 Link encap:Ethernet  HWaddr 02:42:ef:2f:b5:22  
inet addr:x.x.x.1  Bcast:  Mask:

x.x.x.1 doesn’t exist.

I have been playing around with setting the --bip setting, to create a custom docker0 with some success. But then I cant use the --IP setting on a container, as it says it’s not a user defined network.


I switched to the Macvlan driver

If I were doing this, I’d assign all 10 addresses to the host, and docker run -p has a field to say which specific address a container is bound to. I’d otherwise use the default networking and the normal network driver. Something like:

sudo ip addr add x.x.x.92 dev eth0
sudo docker run -p x.x.x.92:80:8000 -d ...