wait.go 918 B

1234567891011121314151617181920212223242526272829303132333435
  1. package client
  2. import (
  3. "fmt"
  4. Cli "github.com/docker/docker/cli"
  5. flag "github.com/docker/docker/pkg/mflag"
  6. )
  7. // CmdWait blocks until a container stops, then prints its exit code.
  8. //
  9. // If more than one container is specified, this will wait synchronously on each container.
  10. //
  11. // Usage: docker wait CONTAINER [CONTAINER...]
  12. func (cli *DockerCli) CmdWait(args ...string) error {
  13. cmd := Cli.Subcmd("wait", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["wait"].Description, true)
  14. cmd.Require(flag.Min, 1)
  15. cmd.ParseFlags(args, true)
  16. var errNames []string
  17. for _, name := range cmd.Args() {
  18. status, err := cli.client.ContainerWait(name)
  19. if err != nil {
  20. fmt.Fprintf(cli.err, "%s\n", err)
  21. errNames = append(errNames, name)
  22. } else {
  23. fmt.Fprintf(cli.out, "%d\n", status)
  24. }
  25. }
  26. if len(errNames) > 0 {
  27. return fmt.Errorf("Error: failed to wait containers: %v", errNames)
  28. }
  29. return nil
  30. }