Docker Community Forums

Share and learn in the Docker community.

Making containers addressable on the same network as host?


(Gunnarniels) #1

I’ve found a lot of talk about this but nothing has seemed to work out for me, but this doesn’t seem like an unusual usecase…

I have a fresh CentOS7 bare metal server with docker version

Docker version 1.10.3, build cb079f6-unsupported
My LAN is 192.168.1.0/24, and my server statically lives at 192.168.1.2 on that network. All I want to do is to be able to bring up containers at specified static addresses, so 192.168.1.3 etc., and have these be accessible from other machines on the same network, like my laptop.

I have read that this can be accomplished via bridges, so I’ve configured a bridge using the one ethernet port on the server:

[arthas@arthas docker]$ cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
ONBOOT=yes
ETHTOOL_OPTS="autoneg off speed 100 duplex full"
BRIDGE=br0
HWADDR=20:cf:30:3a:2a:ca

[arthas@arthas docker]$ cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.2
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=192.168.1.1
DELAY=0

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000
    link/ether 20:cf:30:3a:2a:ca brd ff:ff:ff:ff:ff:ff
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 20:cf:30:3a:2a:ca brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.2/24 brd 192.168.1.255 scope global br0
       valid_lft forever preferred_lft forever

This all works fine, but I’m not sure of the correct way to coerce docker to use this bridge and allow me to assign ips to it. I tried using -b=br0 in the startup option, but the containers I brought up have no outside connection. I’ve also tried assigning specific ips to the containers via -ip 192.168.1.3, but I also had no luck there.

Could anyone point me in the right direction here? I want to make sure I do this the right way and that it’s persistent.