Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 740
tgogos Avatar asked May 15 '17 13:05

tgogos


People also ask

How do I specify a network in Docker?

Manage a user-defined bridgeUse the docker network create command to create a user-defined bridge network. You can specify the subnet, the IP address range, the gateway, and other options. See the docker network create reference or the output of docker network create --help for details.


1 Answers

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
like image 78
tgogos Avatar answered Oct 21 '22 06:10

tgogos