Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/command/container/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*networktypes.End
LinkLocalIPs: ep.LinkLocalIPs,
}
}
epConfig.Priority = ep.Priority
return epConfig, nil
}

Expand Down
3 changes: 3 additions & 0 deletions cli/command/network/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type connectOptions struct {
aliases []string
linklocalips []string
driverOpts []string
priority int
}

func newConnectCommand(dockerCli command.Cli) *cobra.Command {
Expand All @@ -46,6 +47,7 @@ func newConnectCommand(dockerCli command.Cli) *cobra.Command {
flags.StringSliceVar(&options.aliases, "alias", []string{}, "Add network-scoped alias for the container")
flags.StringSliceVar(&options.linklocalips, "link-local-ip", []string{}, "Add a link-local address for the container")
flags.StringSliceVar(&options.driverOpts, "driver-opt", []string{}, "driver options for the network")
flags.IntVar(&options.priority, "priority", 0, "Set network priority (default 0)")
return cmd
}

Expand All @@ -65,6 +67,7 @@ func runConnect(dockerCli command.Cli, options connectOptions) error {
Links: options.links.GetAll(),
Aliases: options.aliases,
DriverOpts: driverOpts,
Priority: options.priority,
}

return client.NetworkConnect(context.Background(), options.network, options.container, epConfig)
Expand Down
9 changes: 9 additions & 0 deletions opts/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/csv"
"fmt"
"regexp"
"strconv"
"strings"
)

Expand All @@ -13,6 +14,7 @@ const (
networkOptIPv4Address = "ip"
networkOptIPv6Address = "ip6"
driverOpt = "driver-opt"
networkPriority = "priority"
)

// NetworkAttachmentOpts represents the network options for endpoint creation
Expand All @@ -24,6 +26,7 @@ type NetworkAttachmentOpts struct {
IPv4Address string
IPv6Address string
LinkLocalIPs []string // TODO add support for LinkLocalIPs in the csv notation of `--network` ?
Priority int
}

// NetworkOpt represents a network config in swarm mode.
Expand Down Expand Up @@ -76,6 +79,12 @@ func (n *NetworkOpt) Set(value string) error {
} else {
return err
}
case networkPriority:
prior, err := strconv.Atoi(value)
if err != nil {
return fmt.Errorf("invalid priority value %s", value)
}
netOpt.Priority = prior
default:
return fmt.Errorf("invalid field key %s", key)
}
Expand Down