1
0
mirror of https://github.com/docker/cli.git synced 2026-01-15 07:40:57 +03:00

'docker ps' lists running containers. 'docker ps -a' also includes stopped containers

Upstream-commit: 903f091adc3878f9e08874dd4b748ae10853cbd3
Component: engine
This commit is contained in:
Solomon Hykes
2013-01-28 23:13:58 -08:00
parent 9f3880a4db
commit 64d5611a9c

View File

@@ -30,7 +30,7 @@ func (srv *Server) Help() string {
help := "Usage: docker COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n"
for _, cmd := range [][]interface{}{
{"run", "Run a command in a container"},
{"list", "Display a list of containers"},
{"ps", "Display a list of containers"},
{"pull", "Download a tarball and create a container from it"},
{"put", "Upload a tarball and create a container from it"},
{"rm", "Remove containers"},
@@ -317,11 +317,11 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri
}
func (srv *Server) CmdContainers(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
cmd := rcli.Subcmd(stdout,
"containers", "[OPTIONS]",
"List containers")
"ps", "[OPTIONS]", "List containers")
quiet := cmd.Bool("q", false, "Only display numeric IDs")
fl_all := cmd.Bool("a", false, "Show all containers. Only running containers are shown by default.")
if err := cmd.Parse(args); err != nil {
return nil
}
@@ -330,6 +330,9 @@ func (srv *Server) CmdContainers(stdin io.ReadCloser, stdout io.Writer, args ...
fmt.Fprintf(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\n")
}
for _, container := range srv.containers.List() {
if !container.State.Running && !*fl_all {
continue
}
if !*quiet {
for idx, field := range[]string {
/* ID */ container.Id,