mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #1812 from dotcloud/return-run-exit-code
*Client: Return the process exit code for run commands
This commit is contained in:
commit
9b088ada7e
1 changed files with 23 additions and 7 deletions
30
commands.go
30
commands.go
|
@ -367,16 +367,11 @@ func (cli *DockerCli) CmdWait(args ...string) error {
|
|||
return nil
|
||||
}
|
||||
for _, name := range cmd.Args() {
|
||||
body, _, err := cli.call("POST", "/containers/"+name+"/wait", nil)
|
||||
status, err := waitForExit(cli, name)
|
||||
if err != nil {
|
||||
fmt.Fprintf(cli.err, "%s", err)
|
||||
} else {
|
||||
var out APIWait
|
||||
err = json.Unmarshal(body, &out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(cli.out, "%d\n", out.StatusCode)
|
||||
fmt.Fprintf(cli.out, "%d\n", status)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -1477,8 +1472,16 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|||
}
|
||||
|
||||
if !config.AttachStdout && !config.AttachStderr {
|
||||
// Detached mode
|
||||
<-wait
|
||||
} else {
|
||||
status, err := waitForExit(cli, runResult.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
os.Exit(status)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -1759,6 +1762,19 @@ func (cli *DockerCli) LoadConfigFile() (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
func waitForExit(cli *DockerCli, containerId string) (int, error) {
|
||||
body, _, err := cli.call("POST", "/containers/"+containerId+"/wait", nil)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
var out APIWait
|
||||
if err := json.Unmarshal(body, &out); err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return out.StatusCode, nil
|
||||
}
|
||||
|
||||
func NewDockerCli(in io.ReadCloser, out, err io.Writer, proto, addr string) *DockerCli {
|
||||
var (
|
||||
isTerminal = false
|
||||
|
|
Loading…
Reference in a new issue