This repository was archived by the owner on Oct 13, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
components/cli/cli/command/container Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66 "fmt"
77 "io/ioutil"
88 "path"
9+ "reflect"
910 "regexp"
1011 "strconv"
1112 "strings"
@@ -707,6 +708,15 @@ func parseNetworkOpts(copts *containerOptions) (map[string]*networktypes.Endpoin
707708 if _ , ok := endpoints [n .Target ]; ok {
708709 return nil , errdefs .InvalidParameter (errors .Errorf ("network %q is specified multiple times" , n .Target ))
709710 }
711+
712+ // For backward compatibility: if no custom options are provided for the network,
713+ // and only a single network is specified, omit the endpoint-configuration
714+ // on the client (the daemon will still create it when creating the container)
715+ if i == 0 && len (copts .netMode .Value ()) == 1 {
716+ if ep == nil || reflect .DeepEqual (* ep , networktypes.EndpointSettings {}) {
717+ continue
718+ }
719+ }
710720 endpoints [n .Target ] = ep
711721 }
712722 if hasUserDefined && hasNonUserDefined {
Original file line number Diff line number Diff line change @@ -401,13 +401,13 @@ func TestParseNetworkConfig(t *testing.T) {
401401 {
402402 name : "single-network-legacy" ,
403403 flags : []string {"--network" , "net1" },
404- expected : map [string ]* networktypes.EndpointSettings {"net1" : {} },
404+ expected : map [string ]* networktypes.EndpointSettings {},
405405 expectedCfg : container.HostConfig {NetworkMode : "net1" },
406406 },
407407 {
408408 name : "single-network-advanced" ,
409409 flags : []string {"--network" , "name=net1" },
410- expected : map [string ]* networktypes.EndpointSettings {"net1" : {} },
410+ expected : map [string ]* networktypes.EndpointSettings {},
411411 expectedCfg : container.HostConfig {NetworkMode : "net1" },
412412 },
413413 {
You can’t perform that action at this time.
0 commit comments