diff --git a/cli/command/swarm/init.go b/cli/command/swarm/init.go index 977751d9dc86..3c096c660493 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")`) @@ -69,6 +72,7 @@ func runInit(dockerCli command.Cli, flags *pflag.FlagSet, opts initOptions) erro ListenAddr: opts.listenAddr.String(), AdvertiseAddr: opts.advertiseAddr, DataPathAddr: opts.dataPathAddr, + DataPathPort: opts.dataPathPort, DefaultAddrPool: defaultAddrPool, ForceNewCluster: opts.forceNewCluster, Spec: opts.swarmOptions.ToSpec(flags), 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..a0b76f2a7321 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]: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..429a8c384815 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 uint32 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. --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,32 @@ 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 allows you to configure the UDP port number to use for data path +traffic. The provided port number must be within the 1024 - 49151 range. If +this flag is not set or is set to 0, the default port number 4789 is used. +The data path port can only be configured when initializing the swarm, and +applies to all nodes that join the swarm. +The following example initializes a new Swarm, and configures the data path +port to UDP port 7777; + +```bash +docker swarm init --data-path-port=7777 +``` +After the swarm is initialized, use the `docker info` command to verify that +the port is configured: + +```bash +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`