Merge pull request #6063 from giautm/patch-1

cli/cli: use `len()` to check frontend ports in the `port` command
This commit is contained in:
Sebastiaan van Stijn 2025-05-16 12:03:15 +02:00 committed by GitHub
commit 77fbbc38de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -68,7 +68,7 @@ func runPort(ctx context.Context, dockerCli command.Cli, opts *portOptions) erro
return errors.Wrapf(err, "Error: invalid port (%s)", port) return errors.Wrapf(err, "Error: invalid port (%s)", port)
} }
frontends, exists := c.NetworkSettings.Ports[nat.Port(port+"/"+proto)] frontends, exists := c.NetworkSettings.Ports[nat.Port(port+"/"+proto)]
if !exists || frontends == nil { if !exists || len(frontends) == 0 {
return errors.Errorf("Error: No public port '%s' published for %s", opts.port, opts.container) return errors.Errorf("Error: No public port '%s' published for %s", opts.port, opts.container)
} }
for _, frontend := range frontends { for _, frontend := range frontends {