diff --git a/cli/command/service/formatter.go b/cli/command/service/formatter.go index 5e99acc845..a488b4fcc5 100644 --- a/cli/command/service/formatter.go +++ b/cli/command/service/formatter.go @@ -725,6 +725,7 @@ func (c *serviceContext) Image() string { } type portRange struct { + pName string pStart uint32 pEnd uint32 tStart uint32 @@ -734,10 +735,16 @@ type portRange struct { func (pr portRange) String() string { var ( - pub string - tgt string + pub string + tgt string + name string ) + if pr.pName == "" { + name = "*" + } else { + name = pr.pName + } if pr.pEnd > pr.pStart { pub = fmt.Sprintf("%d-%d", pr.pStart, pr.pEnd) } else { @@ -748,7 +755,7 @@ func (pr portRange) String() string { } else { tgt = fmt.Sprintf("%d", pr.tStart) } - return fmt.Sprintf("*:%s->%s/%s", pub, tgt, pr.protocol) + return fmt.Sprintf("%s:%s->%s/%s", name, pub, tgt, pr.protocol) } // Ports formats published ports on the ingress network for output. @@ -794,6 +801,7 @@ func (c *serviceContext) Ports() string { ports = append(ports, pr.String()) } pr = portRange{ + pName: p.Name, pStart: p.PublishedPort, pEnd: p.PublishedPort, tStart: p.TargetPort, diff --git a/cli/command/task/formatter.go b/cli/command/task/formatter.go index 0958a1e89e..06a5bd6585 100644 --- a/cli/command/task/formatter.go +++ b/cli/command/task/formatter.go @@ -139,7 +139,10 @@ func (c *taskContext) Ports() string { } ports := []string{} for _, pConfig := range c.task.Status.PortStatus.Ports { - ports = append(ports, fmt.Sprintf("*:%d->%d/%s", + var name = pConfig.Name + if name == "" { name = "*" } + ports = append(ports, fmt.Sprintf("%s:%d->%d/%s", + name, pConfig.PublishedPort, pConfig.TargetPort, pConfig.Protocol,