Multicore containers with static addresses

I am working on a project that is usually implemented with virtual machines. But instead I would like to hack docker containers to practice and learn something new.

So, here's what I would like to do: create multiple containers running on the same host, with static IPs linked to each other (but not necessarily linked to the outside world). In other words, I would like to emulate a separate network consisting of several computers connected to a single switch.

I tried modifying / etc / network / interfaces in containers to set static IPs for eth0, docker0, ... But that doesn't affect the system in any way. I tried using --net = host, --cap-add = NET_ADMIN, but it didn't help.

It drives me crazy. SOS! Thanks to

EDIT: Important stuff I didn't say: I am using my Mac Book Air and I am running boot2docker (which creates a virtual machine with a dock). When I run the image with "docker run -i -t ubuntu / bin / bash", I don't have docker0 as the interface: when I run "ip a", only lo and eth0 are displayed in the container.

+3


source to share


1 answer


Why did you try --net=host

? This setting completely disables network isolation and starts the container in the default namespace. This means that docker containers can see all of the host's network interfaces. I think this is not your option.

It's important to explain how docker deals with isolated networks. First of all, it creates a named bridge docker0

(at least by default). Every time a container is started with an isolated network (i.e. without --net=host

), docker creates a couple of interfaces veth

. One of these front-end docker provides a container (if you run ip link list

in your container, you will see this very virtual interface). Another docker connects to the bridge docker0

(by the way, you can tell which bridge to use by passing the -b $ {BRIDGE} option to the docker daemon).

I would recommend you read the article on docker bridges and this one on namespaces .



Try running containers with an isolated network and then assign a static IP address that you like. But be aware of routing. The host must have a route to the subnet where your containers are running. The easiest way to do this (and only adequate for me) is to assign you IP containers from the same subnet as the docker bridge.

The 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

      

+2


source







All Articles