Docker - how to set iface name when creating a new network

tgogos picture tgogos · May 15, 2017 · Viewed 9k times · Source

After creating a new network with:

docker network create test-net

and running ifconfig on the host, a new interface name is being listed:

br-f2b630e4e141 Link encap:Ethernet  HWaddr 02:42:48:fe:cb:86  
          inet addr:172.18.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          UP BROADCAST MULTICAST  MTU:1500  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)
  1. Is there a way to create this network and specify the iface name, for example docker1 or test-net?

  2. In case of docker-compose, can we also specify iface name inside the docker-compose.yml file?

Answer

tgogos picture tgogos · May 15, 2017

1. with docker network command

There is a --opt option which can be used like this:

docker network create --opt com.docker.network.bridge.name=br_test test-net

and it seems to work:

$ ifconfig
br_test   Link encap:Ethernet  HWaddr 02:42:8f:3b:24:32  
          inet addr:172.18.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          UP BROADCAST MULTICAST  MTU:1500  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)

found about --opt here: https://docs.docker.com/engine/userguide/networking/#the-dockergwbridge-network

2. with docker-compose

inside the docker-compose.yml:

networks:
  test-net:
    driver: bridge
    ipam:
     driver: default
     config:
       - subnet: 172.100.0.0/16
    driver_opts:
      com.docker.network.bridge.name: br_test