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

1

22

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?

Stockyard answered 15/5, 2017 at 13:47 Comment(2)
Have you checked documentationBain
@Rao, I checked again and it seems I've found something :-)Stockyard
S
46

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
Stockyard answered 15/5, 2017 at 14:19 Comment(5)
Please specify the version of docker-compose where this option: com.docker.network.bridge.name is applicable.Siebert
@Siebert found that it still applicable docs.docker.com/v17.09/engine/userguide/networking/…Valadez
Notice: error failed to check bridge interface existence: numerical result out of range means the specified interface name is too long.Megillah
version 3.7 worksSternberg
com.docker.network.container_iface_prefix: NAME can be used to set the network iface name in the containerDipietro

© 2022 - 2024 — McMap. All rights reserved.