func (cli *DockerCli) CmdPs(args ...string) error {
	var (
		err error

		psFilterArgs = filters.Args{}
		v            = url.Values{}

		cmd      = Cli.Subcmd("ps", nil, Cli.DockerCommands["ps"].Description, true)
		quiet    = cmd.Bool([]string{"q", "-quiet"}, false, "Only display numeric IDs")
		size     = cmd.Bool([]string{"s", "-size"}, false, "Display total file sizes")
		all      = cmd.Bool([]string{"a", "-all"}, false, "Show all containers (default shows just running)")
		noTrunc  = cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
		nLatest  = cmd.Bool([]string{"l", "-latest"}, false, "Show the latest created container, include non-running")
		since    = cmd.String([]string{"#sinceId", "#-since-id", "-since"}, "", "Show created since Id or Name, include non-running")
		before   = cmd.String([]string{"#beforeId", "#-before-id", "-before"}, "", "Show only container created before Id or Name")
		last     = cmd.Int([]string{"n"}, -1, "Show n last created containers, include non-running")
		format   = cmd.String([]string{"-format"}, "", "Pretty-print containers using a Go template")
		flFilter = opts.NewListOpts(nil)
	)
	cmd.Require(flag.Exact, 0)

	cmd.Var(&flFilter, []string{"f", "-filter"}, "Filter output based on conditions provided")

	cmd.ParseFlags(args, true)
	if *last == -1 && *nLatest {
		*last = 1
	}

	if *all {
		v.Set("all", "1")
	}

	if *last != -1 {
		v.Set("limit", strconv.Itoa(*last))
	}

	if *since != "" {
		v.Set("since", *since)
	}

	if *before != "" {
		v.Set("before", *before)
	}

	if *size {
		v.Set("size", "1")
	}

	// Consolidate all filter flags, and sanity check them.
	// They'll get processed in the daemon/server.
	for _, f := range flFilter.GetAll() {
		if psFilterArgs, err = filters.ParseFlag(f, psFilterArgs); err != nil {
			return err
		}
	}

	if len(psFilterArgs) > 0 {
		filterJSON, err := filters.ToParam(psFilterArgs)
		if err != nil {
			return err
		}

		v.Set("filters", filterJSON)
	}

	serverResp, err := cli.call("GET", "/containers/json?"+v.Encode(), nil, nil)
	if err != nil {
		return err
	}

	defer serverResp.body.Close()

	containers := []types.Container{}
	if err := json.NewDecoder(serverResp.body).Decode(&containers); err != nil {
		return err
	}

	f := *format
	if len(f) == 0 {
		if len(cli.PsFormat()) > 0 && !*quiet {
			f = cli.PsFormat()
		} else {
			f = "table"
		}
	}

	psCtx := ps.Context{
		Output: cli.out,
		Format: f,
		Quiet:  *quiet,
		Size:   *size,
		Trunc:  !*noTrunc,
	}

	ps.Format(psCtx, containers)

	return nil
}
// CmdPs outputs a list of Docker containers.
//
// Usage: docker ps [OPTIONS]
CmdPs outputs a list of Docker containers.

docker ps [OPTIONS]
// CmdPs outputs a list of Docker containers . // // Usage : docker ps [ OPTIONS ]
func (cli *DockerCli) CmdPs(args ...string) error {
	var (
		err error
		psFilterArgs = filters.Args{}
		v            = url.Values{}
		cmd      = Cli.Subcmd("ps", nil, Cli.DockerCommands["ps"].Description, true)
		quiet    = cmd.Bool([]string{"q", "-quiet"}, false, "Only display numeric IDs")
		size     = cmd.Bool([]string{"s", "-size"}, false, "Display total file sizes")
		all      = cmd.Bool([]string{"a", "-all"}, false, "Show all containers (default shows just running)")
		noTrunc  = cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
		nLatest  = cmd.Bool([]string{"l", "-latest"}, false, "Show the latest created container, include non-running")
		since    = cmd.String([]string{"#sinceId", "#-since-id", "-since"}, "", "Show created since Id or Name, include non-running")
		before   = cmd.String([]string{"#beforeId", "#-before-id", "-before"}, "", "Show only container created before Id or Name")
		last     = cmd.Int([]string{"n"}, -1, "Show n last created containers, include non-running")
		format   = cmd.String([]string{"-format"}, "", "Pretty-print containers using a Go template")
		flFilter = opts.NewListOpts(nil)
	)
	cmd.Require(flag.Exact, 0)
	cmd.Var(&flFilter, []string{"f", "-filter"}, "Filter output based on conditions provided")
	cmd.ParseFlags(args, true)
	if *last == -1 && *nLatest {
		*last = 1
	}
	if *all {
		v.Set("all", "1")
	}
	if *last != -1 {
		v.Set("limit", strconv.Itoa(*last))
	}
	if *since != "" {
		v.Set("since", *since)
	}
	if *before != "" {
		v.Set("before", *before)
	}
	if *size {
		v.Set("size", "1")
	}
	for _, f := range flFilter.GetAll() {
		if psFilterArgs, err = filters.ParseFlag(f, psFilterArgs); err != nil {
			return err
		}
	}
	if len(psFilterArgs) > 0 {
		filterJSON, err := filters.ToParam(psFilterArgs)
		if err != nil {
			return err
		}
		v.Set("filters", filterJSON)
	}
	serverResp, err := cli.call("GET", "/containers/json?"+v.Encode(), nil, nil)
	if err != nil {
		return err
	}
	defer serverResp.body.Close()
	containers := []types.Container{}
	if err := json.NewDecoder(serverResp.body).Decode(&containers); err != nil {
		return err
	}
	f := *format
	if len(f) == 0 {
		if len(cli.PsFormat()) > 0 && !*quiet {
			f = cli.PsFormat()
		} else {
			f = "table"
		}
	}
	psCtx := ps.Context{
		Output: cli.out,
		Format: f,
		Quiet:  *quiet,
		Size:   *size,
		Trunc:  !*noTrunc,
	}
	ps.Format(psCtx, containers)
	return nil
}
func ( cli * DockerCli ) CmdPs ( args ... string ) error { var ( err error psFilterArgs = filters . Args { } v = url . Values { } cmd = Cli . Subcmd ( " " , nil , Cli . DockerCommands [ " " ] . Description , true ) quiet = cmd . Bool ( [ ] string { " " , " " } , false , " " ) size = cmd . Bool ( [ ] string { " " , " " } , false , " " ) all = cmd . Bool ( [ ] string { " " , " " } , false , " " ) noTrunc = cmd . Bool ( [ ] string { " " , " " } , false , " " ) nLatest = cmd . Bool ( [ ] string { " " , " " } , false , " " ) since = cmd . String ( [ ] string { " " , " " , " " } , " " , " " ) before = cmd . String ( [ ] string { " " , " " , " " } , " " , " " ) last = cmd . Int ( [ ] string { " " } , - 1 , " " ) format = cmd . String ( [ ] string { " " } , " " , " " ) flFilter = opts . NewListOpts ( nil ) ) cmd . Require ( flag . Exact , 0 ) cmd . Var ( & flFilter , [ ] string { " " , " " } , " " ) cmd . ParseFlags ( args , true ) if * last == - 1 && * nLatest { * last = 1 } if * all { v . Set ( " " , " " ) } if * last != - 1 { v . Set ( " " , strconv . Itoa ( * last ) ) } if * since != " " { v . Set ( " " , * since ) } if * before != " " { v . Set ( " " , * before ) } if * size { v . Set ( " " , " " ) } for _ , f := range flFilter . GetAll ( ) { if psFilterArgs , err = filters . ParseFlag ( f , psFilterArgs ) ; err != nil { return err } } if len ( psFilterArgs ) > 0 { filterJSON , err := filters . ToParam ( psFilterArgs ) if err != nil { return err } v . Set ( " " , filterJSON ) } serverResp , err := cli . call ( " " , " " + v . Encode ( ) , nil , nil ) if err != nil { return err } defer serverResp . body . Close ( ) containers := [ ] types . Container { } if err := json . NewDecoder ( serverResp . body ) . Decode ( & containers ) ; err != nil { return err } f := * format if len ( f ) == 0 { if len ( cli . PsFormat ( ) ) > 0 && ! * quiet { f = cli . PsFormat ( ) } else { f = " " } } psCtx := ps . Context { Output : cli . out , Format : f , Quiet : * quiet , Size : * size , Trunc : ! * noTrunc , } ps . Format ( psCtx , containers ) return nil }
CmdPs outputs a list of Docker containers.
CmdPs outputs a list of Docker containers .
// Consolidate all filter flags, and sanity check them. // They'll get processed in the daemon/server.