I am working on a project usually implemented with VMs. But I would like to hack with docker containers instead, in order to practice and learn something new.
So here is what I would like to do : create several containers running on the same host, with static ip addresses, connected one to each others (but not necessarily connected to the outside world). In other words, I would like emulate kind of a stand alone network, composed of several computers connected to the same switch.
I tried to change /etc/network/interfaces in containers to set static ip addresses for eth0, docker0, ... But it doesn't affect the system in any way. I tried to use --net=host, --cap-add=NET_ADMIN but it didn't help.
It's driving me crazy. SOS! Thanks
EDIT : Important stuff I didn't say : I'm using my Mac Book Air, and I am running boot2docker (which creates a VM running docker). When I run an image with "docker run -i -t ubuntu /bin/bash", I don't have docker0 as an interface : running "ip a" in the container displays only lo and eth0.
Why did you try --net=host? This option disables network isolation at all, and runs container in default network namespace. This means that docker containers can see all host network interfaces. I think this is not your option.
There is important to tell, how docker deals with isolated networks. First of all, it creates bridge named docker0 (at least by default). Each time when you starting container with isolated network (i.e., without --net=host), docker creates a pair of veth interfaces. One of this interface docker gives to container (if you'll run ip link list in your container, you will see exactly this virtual interface). Another one docker plugs in bridge docker0 (by the way, you can say which bridge to use by passing "-b ${BRIDGE}" option to docker daemon).
I'd recommend you to read article about docker bridges and this one about network namespaces.
Try to run containers with isolated networking, and then assign static IP that you like. But be aware of routing - host must have route to subnet, where your containers running. Easiest way to do this (and the only adequate as for me) - assign to you containers IP from same subnet as docker bridge.
Following example works well for me.
user@host$ ip addr
docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 56:84:7a:fe:97:99 brd ff:ff:ff:ff:ff:ff
inet 172.17.42.1/16 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::5484:7aff:fefe:9799/64 scope link
valid_lft forever preferred_lft forever
root@docker-1# ip addr
eth0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.2/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:2/64 scope link
valid_lft forever preferred_lft forever
root@docker-2# ip addr
eth0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 02:42:ac:11:00:05 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.3/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:5/64 scope link
valid_lft forever preferred_lft forever
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With