diff --git a/api/server/router/network/network_routes.go b/api/server/router/network/network_routes.go index 7e5b94cb91..ebf2ce2872 100644 --- a/api/server/router/network/network_routes.go +++ b/api/server/router/network/network_routes.go @@ -81,6 +81,10 @@ func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWr return err } + if _, err := n.clusterProvider.GetNetwork(create.Name); err == nil { + return libnetwork.NetworkNameError(create.Name) + } + nw, err := n.backend.CreateNetwork(create) if err != nil { if _, ok := err.(libnetwork.ManagerRedirectError); !ok { diff --git a/daemon/network.go b/daemon/network.go index a9944e637c..af10723383 100644 --- a/daemon/network.go +++ b/daemon/network.go @@ -292,6 +292,10 @@ func (daemon *Daemon) UpdateContainerServiceConfig(containerName string, service return nil } +func errClusterNetworkConnect() error { + return fmt.Errorf("cannot connect or disconnect managed containers on a network") +} + // ConnectContainerToNetwork connects the given container to the given // network. If either cannot be found, an err is returned. If the // network cannot be set up, an err is returned. @@ -300,6 +304,9 @@ func (daemon *Daemon) ConnectContainerToNetwork(containerName, networkName strin if err != nil { return err } + if container.Managed { + return errClusterNetworkConnect() + } return daemon.ConnectToNetwork(container, networkName, endpointConfig) } @@ -313,6 +320,9 @@ func (daemon *Daemon) DisconnectContainerFromNetwork(containerName string, netwo } return err } + if container.Managed { + return errClusterNetworkConnect() + } return daemon.DisconnectFromNetwork(container, network, force) }