diff --git a/cli/command/swarm/init.go b/cli/command/swarm/init.go index 977751d9dc86..d56de4e36721 100644 --- a/cli/command/swarm/init.go +++ b/cli/command/swarm/init.go @@ -20,6 +20,7 @@ type initOptions struct { // Not a NodeAddrOption because it has no default port. advertiseAddr string dataPathAddr string + dataPathPort uint32 forceNewCluster bool availability string defaultAddrPools []net.IPNet @@ -45,6 +46,8 @@ func newInitCommand(dockerCli command.Cli) *cobra.Command { flags.StringVar(&opts.advertiseAddr, flagAdvertiseAddr, "", "Advertised address (format: [:port])") flags.StringVar(&opts.dataPathAddr, flagDataPathAddr, "", "Address or interface to use for data path traffic (format: )") flags.SetAnnotation(flagDataPathAddr, "version", []string{"1.31"}) + flags.Uint32Var(&opts.dataPathPort, flagDataPathPort, 0, "Port number to use for data path traffic (1024 - 49151). If no value is set or is set to 0, the default port (4789) is used.") + flags.SetAnnotation(flagDataPathPort, "version", []string{"1.40"}) flags.BoolVar(&opts.forceNewCluster, "force-new-cluster", false, "Force create a new cluster from current state") flags.BoolVar(&opts.autolock, flagAutolock, false, "Enable manager autolocking (requiring an unlock key to start a stopped manager)") flags.StringVar(&opts.availability, flagAvailability, "active", `Availability of the node ("active"|"pause"|"drain")`) @@ -74,6 +77,7 @@ func runInit(dockerCli command.Cli, flags *pflag.FlagSet, opts initOptions) erro Spec: opts.swarmOptions.ToSpec(flags), AutoLockManagers: opts.swarmOptions.autolock, SubnetSize: opts.DefaultAddrPoolMaskLength, + DataPathPort: opts.dataPathPort, } if flags.Changed(flagAvailability) { availability := swarm.NodeAvailability(strings.ToLower(opts.availability)) diff --git a/cli/command/swarm/opts.go b/cli/command/swarm/opts.go index 9d1ea4c47d42..ea66bf398769 100644 --- a/cli/command/swarm/opts.go +++ b/cli/command/swarm/opts.go @@ -22,6 +22,7 @@ const ( flagListenAddr = "listen-addr" flagAdvertiseAddr = "advertise-addr" flagDataPathAddr = "data-path-addr" + flagDataPathPort = "data-path-port" flagDefaultAddrPool = "default-addr-pool" flagDefaultAddrPoolMaskLength = "default-addr-pool-mask-length" flagQuiet = "quiet" diff --git a/cli/command/system/info.go b/cli/command/system/info.go index 92fc2cd3e77a..2d6ac31ccc0b 100644 --- a/cli/command/system/info.go +++ b/cli/command/system/info.go @@ -235,6 +235,9 @@ func printSwarmInfo(dockerCli command.Cli, info types.Info) { fmt.Fprintln(dockerCli.Out(), " Default Address Pool:", strAddrPool.String()) fmt.Fprintln(dockerCli.Out(), " SubnetSize:", info.Swarm.Cluster.SubnetSize) } + if info.Swarm.Cluster.DataPathPort > 0 { + fmt.Fprintln(dockerCli.Out(), " Data Path Port:", info.Swarm.Cluster.DataPathPort) + } fmt.Fprintln(dockerCli.Out(), " Orchestration:") taskHistoryRetentionLimit := int64(0) diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 897be6f9793f..18f08191e070 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -3698,7 +3698,7 @@ _docker_swarm_init() { COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) ) return ;; - --cert-expiry|--default-addr-pool|--default-addr-pool-mask-length|--dispatcher-heartbeat|--external-ca|--max-snapshots|--snapshot-interval|--task-history-limit ) + --cert-expiry|--data-path-port|--default-addr-pool|--default-addr-pool-mask-length|--dispatcher-heartbeat|--external-ca|--max-snapshots|--snapshot-interval|--task-history-limit ) return ;; --data-path-addr) @@ -3718,7 +3718,7 @@ _docker_swarm_init() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--advertise-addr --autolock --availability --cert-expiry --data-path-addr --default-addr-pool --default-addr-pool-mask-length --dispatcher-heartbeat --external-ca --force-new-cluster --help --listen-addr --max-snapshots --snapshot-interval --task-history-limit" -- "$cur" ) ) + COMPREPLY=( $( compgen -W "--advertise-addr --autolock --availability --cert-expiry --data-path-addr --data-path-port --default-addr-pool --default-addr-pool-mask-length --dispatcher-heartbeat --external-ca --force-new-cluster --help --listen-addr --max-snapshots --snapshot-interval --task-history-limit " -- "$cur" ) ) ;; esac } diff --git a/contrib/completion/zsh/_docker b/contrib/completion/zsh/_docker index 94f042204dfb..866a4b689ac0 100644 --- a/contrib/completion/zsh/_docker +++ b/contrib/completion/zsh/_docker @@ -2285,6 +2285,7 @@ __docker_swarm_subcommand() { $opts_help \ "($help)--advertise-addr=[Advertised address]:ip\:port: " \ "($help)--data-path-addr=[Data path IP or interface]:ip " \ + "($help)--data-path-port=[Data Path Port] " \ "($help)--default-addr-pool=[Default address pool]" \ "($help)--default-addr-pool-mask-length=[Default address pool subnet mask length]" \ "($help)--autolock[Enable manager autolocking]" \ diff --git a/docs/reference/commandline/swarm_init.md b/docs/reference/commandline/swarm_init.md index c034c43ba69d..bdc480c06a2c 100644 --- a/docs/reference/commandline/swarm_init.md +++ b/docs/reference/commandline/swarm_init.md @@ -26,6 +26,7 @@ Options: --availability string Availability of the node ("active"|"pause"|"drain") (default "active") --cert-expiry duration Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s) --data-path-addr string Address or interface to use for data path traffic (format: ) + --data-path-port uint Data path port number used for data path traffic --default-addr-pool IPnet List of default address pool (format: ) --default-addr-pool-mask-length Subnet mask length for default address pool (default 24) --dispatcher-heartbeat duration Dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s) @@ -130,6 +131,21 @@ management traffic of the cluster. If unspecified, Docker will use the same IP address or interface that is used for the advertise address. +### `--data-path-port` + +This flag specifies data path port number to use for data path traffic (1024 - 49151). +If no value is set or is set to 0, the default port (4789) is used. This value is set for per cluster +so the option is supported only via swarm init command. swarm update or swarm join commands do not support +this option. The port is reserved for UDP traffic. +Format example is `docker swarm init --data-path-addr=20.20.20.1 --data-path-port=7777` + +Docker info output will display currently used port for data path traffic. + Docker info # + ClusterID: 9vs5ygs0gguyyec4iqf2314c0 + Managers: 1 + Nodes: 1 + Data Path Port: 7777 + ### `--default-addr-pool` This flag specifies default subnet pools for global scope networks. Format example is `--default-addr-pool 30.30.0.0/16 --default-addr-pool 40.40.0.0/16`