Skip to content

Commit f1048e1

Browse files
committed
Create default EndpointSettings if no --network provided
Following flags are silently ignored when they're passed with no `--network` specified (ie. when the default network is used): - `--network-alias` - `--ip` - `--ip6` - `--link-local-ip` This is not really an issue right now since the first 3 parameters are not allowed on the default bridge network. However, with [moby/moby#45905][1], the container-wide MacAddress parameter will be deprecated and dismissed. Because of that, with [#4419][2], it's currently not possible to use the `--mac-address` flag with no default network specified. Morever, `docker network connect --link-local-ip ...` works properly, so it should also work on `docker container create`. This also lay the ground for making the default bridge network just a "normal" network. Since the 3 parameters in the list above aren't ignored anymore, if users provide them, moby's ContainerStart endpoint will complain about those. To provide better UX, [moby/moby#46183][3] make sure these invalid parameters lead to a proper error message on `docker container create` / `docker run`. [1]: moby/moby#45905 [2]: #4419 [3]: moby/moby#46183 Signed-off-by: Albin Kerouanton <albinker@gmail.com>
1 parent d4aca90 commit f1048e1

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

cli/command/container/opts.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,20 @@ func parseNetworkOpts(copts *containerOptions) (map[string]*networktypes.Endpoin
732732
hasUserDefined, hasNonUserDefined bool
733733
)
734734

735+
if len(copts.netMode.Value()) == 0 {
736+
n := opts.NetworkAttachmentOpts{
737+
Target: "default",
738+
}
739+
if err := applyContainerOptions(&n, copts); err != nil {
740+
return nil, err
741+
}
742+
ep, err := parseNetworkAttachmentOpt(n)
743+
if err != nil {
744+
return nil, err
745+
}
746+
endpoints["default"] = ep
747+
}
748+
735749
for i, n := range copts.netMode.Value() {
736750
n := n
737751
if container.NetworkMode(n.Target).IsUserDefined() {
@@ -792,7 +806,7 @@ func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOption
792806
n.Aliases = make([]string, copts.aliases.Len())
793807
copy(n.Aliases, copts.aliases.GetAll())
794808
}
795-
if copts.links.Len() > 0 {
809+
if n.Target != "default" && copts.links.Len() > 0 {
796810
n.Links = make([]string, copts.links.Len())
797811
copy(n.Links, copts.links.GetAll())
798812
}

0 commit comments

Comments
 (0)