|
@@ -20,6 +20,7 @@ import (
|
|
|
"path/filepath"
|
|
|
"reflect"
|
|
|
"runtime"
|
|
|
+ "sort"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"syscall"
|
|
@@ -996,6 +997,19 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+func displayablePorts(ports []APIPort) string {
|
|
|
+ result := []string{}
|
|
|
+ for _, port := range ports {
|
|
|
+ if port.Type == "tcp" {
|
|
|
+ result = append(result, fmt.Sprintf("%d->%d", port.PublicPort, port.PrivatePort))
|
|
|
+ } else {
|
|
|
+ result = append(result, fmt.Sprintf("%d->%d/%s", port.PublicPort, port.PrivatePort, port.Type))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sort.Strings(result)
|
|
|
+ return strings.Join(result, ", ")
|
|
|
+}
|
|
|
+
|
|
|
func (cli *DockerCli) CmdPs(args ...string) error {
|
|
|
cmd := Subcmd("ps", "[OPTIONS]", "List containers")
|
|
|
quiet := cmd.Bool("q", false, "Only display numeric IDs")
|
|
@@ -1053,9 +1067,9 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
|
|
for _, out := range outs {
|
|
|
if !*quiet {
|
|
|
if *noTrunc {
|
|
|
- fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\t", out.ID, out.Image, out.Command, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports)
|
|
|
+ fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\t", out.ID, out.Image, out.Command, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, displayablePorts(out.Ports))
|
|
|
} else {
|
|
|
- fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\t", utils.TruncateID(out.ID), out.Image, utils.Trunc(out.Command, 20), utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports)
|
|
|
+ fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\t", utils.TruncateID(out.ID), out.Image, utils.Trunc(out.Command, 20), utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, displayablePorts(out.Ports))
|
|
|
}
|
|
|
if *size {
|
|
|
if out.SizeRootFs > 0 {
|