docker wait: block until a container exits, and print its exit code
This commit is contained in:
parent
8fa07c0e06
commit
ebaa50c4c9
2 changed files with 25 additions and 1 deletions
|
@ -415,11 +415,13 @@ func (container *Container) Restart() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (container *Container) Wait() {
|
||||
// Wait blocks until the container stops running, then returns its exit code.
|
||||
func (container *Container) Wait() int {
|
||||
|
||||
for container.State.Running {
|
||||
container.State.wait()
|
||||
}
|
||||
return container.State.ExitCode
|
||||
}
|
||||
|
||||
func (container *Container) WaitTimeout(timeout time.Duration) error {
|
||||
|
|
|
@ -53,6 +53,7 @@ func (srv *Server) Help() string {
|
|||
{"diff", "Inspect changes on a container's filesystem"},
|
||||
{"commit", "Save the state of a container"},
|
||||
{"attach", "Attach to the standard inputs and outputs of a running container"},
|
||||
{"wait", "Block until a container exits, then print its exit code"},
|
||||
{"info", "Display system-wide information"},
|
||||
{"tar", "Stream the contents of a container as a tar archive"},
|
||||
{"web", "Generate a web UI"},
|
||||
|
@ -63,6 +64,27 @@ func (srv *Server) Help() string {
|
|||
return help
|
||||
}
|
||||
|
||||
// 'docker wait': block until a container stops
|
||||
func (srv *Server) CmdWait(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
||||
cmd := rcli.Subcmd(stdout, "wait", "[OPTIONS] NAME", "Block until a container stops, then print its exit code.")
|
||||
if err := cmd.Parse(args); err != nil {
|
||||
cmd.Usage()
|
||||
return nil
|
||||
}
|
||||
if cmd.NArg() < 1 {
|
||||
cmd.Usage()
|
||||
return nil
|
||||
}
|
||||
for _, name := range cmd.Args() {
|
||||
if container := srv.containers.Get(name); container != nil {
|
||||
fmt.Fprintln(stdout, container.Wait())
|
||||
} else {
|
||||
return errors.New("No such container: " + name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 'docker info': display system-wide information.
|
||||
func (srv *Server) CmdInfo(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
||||
fmt.Fprintf(stdout, "containers: %d\nversion: %s\nimages: %d\n",
|
||||
|
|
Loading…
Add table
Reference in a new issue