From 25c5df276ce0ee34115d97f7c375e56631286b64 Mon Sep 17 00:00:00 2001 From: Roman Dodin Date: Sat, 26 Jun 2021 13:51:02 +0200 Subject: [PATCH] fixed network bridge detection issue --- runtime/docker/docker.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/runtime/docker/docker.go b/runtime/docker/docker.go index 5ee366d2d..054ee6a6b 100644 --- a/runtime/docker/docker.go +++ b/runtime/docker/docker.go @@ -111,7 +111,15 @@ func (c *DockerRuntime) CreateNet(ctx context.Context) (err error) { Config: ipamConfig, } - networkOptions := dockerTypes.NetworkCreate{ + netwOpts := map[string]string{ + "com.docker.network.driver.mtu": c.Mgmt.MTU, + } + + if bridgeName != "" { + netwOpts["com.docker.network.bridge.name"] = bridgeName + } + + opts := dockerTypes.NetworkCreate{ CheckDuplicate: true, Driver: "bridge", EnableIPv6: enableIPv6, @@ -121,13 +129,10 @@ func (c *DockerRuntime) CreateNet(ctx context.Context) (err error) { Labels: map[string]string{ "containerlab": "", }, - Options: map[string]string{ - "com.docker.network.driver.mtu": c.Mgmt.MTU, - "com.docker.network.bridge.name": bridgeName, - }, + Options: netwOpts, } - netCreateResponse, err := c.Client.NetworkCreate(nctx, c.Mgmt.Network, networkOptions) + netCreateResponse, err := c.Client.NetworkCreate(nctx, c.Mgmt.Network, opts) if err != nil { return err } @@ -150,7 +155,7 @@ func (c *DockerRuntime) CreateNet(ctx context.Context) (err error) { case "bridge": bridgeName = "docker0" default: - if _, ok := netResource.Options["com.docker.network.bridge.name"]; ok { + if netResource.Options["com.docker.network.bridge.name"] != "" { bridgeName = netResource.Options["com.docker.network.bridge.name"] } else { bridgeName = "br-" + netResource.ID[:12]