cli/cli/port: use len() to check frontends ports

This ensure the command won't print an empty output if the `frontends` port is nil

Signed-off-by: Giau. Tran Minh <hello@giautm.dev>
This commit is contained in:
Giau. Tran Minh 2025-05-13 03:41:08 +07:00 committed by Giau. Tran Minh
parent 75a57131a8
commit c409383dbc
No known key found for this signature in database
GPG Key ID: CE488BC2CABE5A03

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)
}
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)
}
for _, frontend := range frontends {