Skip to content

make PORTS in nerdctl ps or nerdctl compose ps easier to view. #4338

Open
@haytok

Description

@haytok

What is the problem you're trying to solve

In the latest version, when we start a container specifying multiple port mappings with -p, the following is displayed.

> sudo nerdctl run -d --name nginx -p 22200-22210:22200-22210 nginx
fbe04ad60307165ccfd84aaec5ea1afa6f54bcdcf8200a941ce195a539e8a7ea

> sudo nerdctl ps
CONTAINER ID    IMAGE                             COMMAND                   CREATED          STATUS    PORTS                                                                                                                                                                                                                                                                                           NAMES
fbe04ad60307    docker.io/library/nginx:latest    "/docker-entrypoint.…"    4 seconds ago    Up        0.0.0.0:22200->22200/tcp, 0.0.0.0:22201->22201/tcp, 0.0.0.0:22202->22202/tcp, 0.0.0.0:22203->22203/tcp, 0.0.0.0:22204->22204/tcp, 0.0.0.0:22205->22205/tcp, 0.0.0.0:22206->22206/tcp, 0.0.0.0:22207->22207/tcp, 0.0.0.0:22208->22208/tcp, 0.0.0.0:22209->22209/tcp, 0.0.0.0:22210->22210/tcp    nginx

On the other hand, in Docker, consecutive port mappings are displayed in an easy-to-read manner.

> docker run -d --name nginx -p 22200-22210:22200-22210 nginx
eaf0d0738d61e12bcd8306f2df14937fa752c4a99f60a1c7093e2f5c6bee6b26

> docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED        STATUS                  PORTS                                                                           NAMES
eaf0d0738d61   nginx     "/docker-entrypoint.…"   1 second ago   Up Less than a second   80/tcp, 0.0.0.0:22200-22210->22200-22210/tcp, :::22200-22210->22200-22210/tcp   nginx

Therefore, in this issue, we'll make PORTS in nerdctl ps or nerdctl compose ps easier to view.

Describe the solution you'd like

Fix FormatPorts()

func FormatPorts(labelMap map[string]string) string {
ports, err := portutil.ParsePortsLabel(labelMap)
if err != nil {
log.L.Error(err.Error())
}
if len(ports) == 0 {
return ""
}
strs := make([]string, len(ports))
for i, p := range ports {
strs[i] = fmt.Sprintf("%s:%d->%d/%s", p.HostIP, p.HostPort, p.ContainerPort, p.Protocol)
}
return strings.Join(strs, ", ")
}

Additional context

related discussions

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions