mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
add ps -s
This commit is contained in:
parent
8a131dffb6
commit
bd04d7d475
3 changed files with 26 additions and 8 deletions
6
api.go
6
api.go
|
@ -248,6 +248,10 @@ func getContainersJSON(srv *Server, version float64, w http.ResponseWriter, r *h
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
size, err := getBoolParam(r.Form.Get("size"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
since := r.Form.Get("since")
|
since := r.Form.Get("since")
|
||||||
before := r.Form.Get("before")
|
before := r.Form.Get("before")
|
||||||
n, err := strconv.Atoi(r.Form.Get("limit"))
|
n, err := strconv.Atoi(r.Form.Get("limit"))
|
||||||
|
@ -255,7 +259,7 @@ func getContainersJSON(srv *Server, version float64, w http.ResponseWriter, r *h
|
||||||
n = -1
|
n = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
outs := srv.Containers(all, n, since, before)
|
outs := srv.Containers(all, size, n, since, before)
|
||||||
b, err := json.Marshal(outs)
|
b, err := json.Marshal(outs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
21
commands.go
21
commands.go
|
@ -867,6 +867,7 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
||||||
func (cli *DockerCli) CmdPs(args ...string) error {
|
func (cli *DockerCli) CmdPs(args ...string) error {
|
||||||
cmd := Subcmd("ps", "[OPTIONS]", "List containers")
|
cmd := Subcmd("ps", "[OPTIONS]", "List containers")
|
||||||
quiet := cmd.Bool("q", false, "Only display numeric IDs")
|
quiet := cmd.Bool("q", false, "Only display numeric IDs")
|
||||||
|
size := cmd.Bool("s", false, "Display sizes")
|
||||||
all := cmd.Bool("a", false, "Show all containers. Only running containers are shown by default.")
|
all := cmd.Bool("a", false, "Show all containers. Only running containers are shown by default.")
|
||||||
noTrunc := cmd.Bool("notrunc", false, "Don't truncate output")
|
noTrunc := cmd.Bool("notrunc", false, "Don't truncate output")
|
||||||
nLatest := cmd.Bool("l", false, "Show only the latest created container, include non-running ones.")
|
nLatest := cmd.Bool("l", false, "Show only the latest created container, include non-running ones.")
|
||||||
|
@ -893,6 +894,9 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
||||||
if *before != "" {
|
if *before != "" {
|
||||||
v.Set("before", *before)
|
v.Set("before", *before)
|
||||||
}
|
}
|
||||||
|
if *size {
|
||||||
|
v.Set("size", "1")
|
||||||
|
}
|
||||||
|
|
||||||
body, _, err := cli.call("GET", "/containers/json?"+v.Encode(), nil)
|
body, _, err := cli.call("GET", "/containers/json?"+v.Encode(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -906,7 +910,12 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
|
||||||
if !*quiet {
|
if !*quiet {
|
||||||
fmt.Fprintln(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tPORTS\tSIZE")
|
fmt.Fprint(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tPORTS")
|
||||||
|
if *size {
|
||||||
|
fmt.Fprintln(w, "\tSIZE")
|
||||||
|
} else {
|
||||||
|
fmt.Fprint(w, "\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, out := range outs {
|
for _, out := range outs {
|
||||||
|
@ -916,10 +925,14 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
||||||
} else {
|
} 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, out.Ports)
|
||||||
}
|
}
|
||||||
if out.SizeRootFs > 0 {
|
if *size {
|
||||||
fmt.Fprintf(w, "%s (virtual %s)\n", utils.HumanSize(out.SizeRw), utils.HumanSize(out.SizeRootFs))
|
if out.SizeRootFs > 0 {
|
||||||
|
fmt.Fprintf(w, "%s (virtual %s)\n", utils.HumanSize(out.SizeRw), utils.HumanSize(out.SizeRootFs))
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(w, "%s\n", utils.HumanSize(out.SizeRw))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(w, "%s\n", utils.HumanSize(out.SizeRw))
|
fmt.Fprint(w, "\n")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if *noTrunc {
|
if *noTrunc {
|
||||||
|
|
|
@ -251,7 +251,7 @@ func (srv *Server) ContainerChanges(name string) ([]Change, error) {
|
||||||
return nil, fmt.Errorf("No such container: %s", name)
|
return nil, fmt.Errorf("No such container: %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) Containers(all bool, n int, since, before string) []APIContainers {
|
func (srv *Server) Containers(all, size bool, n int, since, before string) []APIContainers {
|
||||||
var foundBefore bool
|
var foundBefore bool
|
||||||
var displayed int
|
var displayed int
|
||||||
retContainers := []APIContainers{}
|
retContainers := []APIContainers{}
|
||||||
|
@ -285,8 +285,9 @@ func (srv *Server) Containers(all bool, n int, since, before string) []APIContai
|
||||||
c.Created = container.Created.Unix()
|
c.Created = container.Created.Unix()
|
||||||
c.Status = container.State.String()
|
c.Status = container.State.String()
|
||||||
c.Ports = container.NetworkSettings.PortMappingHuman()
|
c.Ports = container.NetworkSettings.PortMappingHuman()
|
||||||
c.SizeRw, c.SizeRootFs = container.GetSize()
|
if size {
|
||||||
|
c.SizeRw, c.SizeRootFs = container.GetSize()
|
||||||
|
}
|
||||||
retContainers = append(retContainers, c)
|
retContainers = append(retContainers, c)
|
||||||
}
|
}
|
||||||
return retContainers
|
return retContainers
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue