sheerun
sheerun

Reputation: 1794

How to specify static ip address for multiple overlay networks in Docker

So I created two overlay networks like so:

docker network create --driver overlay --subnet 10.40.1.0/16 --internal net1
docker network create --driver overlay --subnet 10.50.1.0/16 --internal net2

Now I want to run a container assigning one static ip address from each net

How to do it? The docker doesn't accept multiple --net flags.

Upvotes: 1

Views: 717

Answers (1)

sheerun
sheerun

Reputation: 1794

You can start docker in stopped state, attach networks, and then only then start it:

docker create --name busybox -ti --net net1 --ip 10.40.1.0 busybox ifconfig
docker network connect --ip 10.50.1.0 net2 busybox
docker start -ai busybox

eth0      Link encap:Ethernet  HWaddr 02:42:0A:28:00:05
          inet addr:10.40.0.5  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:aff:fe28:5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1450  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:90 (90.0 B)  TX bytes:90 (90.0 B)

eth1      Link encap:Ethernet  HWaddr 02:42:0A:32:00:05
          inet addr:10.50.0.5  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:aff:fe32:5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1450  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:90 (90.0 B)  TX bytes:90 (90.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Upvotes: 2

Related Questions