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

This commit is contained in:
Solomon Hykes 2013-01-28 23:13:58 -08:00
parent c283ff6675
commit 903f091adc
1 changed files with 7 additions and 4 deletions

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" help := "Usage: docker COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n"
for _, cmd := range [][]interface{}{ for _, cmd := range [][]interface{}{
{"run", "Run a command in a container"}, {"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"}, {"pull", "Download a tarball and create a container from it"},
{"put", "Upload a tarball and create a container from it"}, {"put", "Upload a tarball and create a container from it"},
{"rm", "Remove containers"}, {"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, cmd := rcli.Subcmd(stdout,
"containers", "[OPTIONS]", "ps", "[OPTIONS]", "List containers")
"List containers")
quiet := cmd.Bool("q", false, "Only display numeric IDs") 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 { if err := cmd.Parse(args); err != nil {
return 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") fmt.Fprintf(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\n")
} }
for _, container := range srv.containers.List() { for _, container := range srv.containers.List() {
if !container.State.Running && !*fl_all {
continue
}
if !*quiet { if !*quiet {
for idx, field := range[]string { for idx, field := range[]string {
/* ID */ container.Id, /* ID */ container.Id,