mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Implement getExitCode with standalone client lib.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
51efb1480a
commit
7df71ca31d
3 changed files with 10 additions and 16 deletions
|
@ -1,6 +1,11 @@
|
|||
package lib
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var ErrConnectionFailed = errors.New("Cannot connect to the Docker daemon. Is the docker daemon running on this host?")
|
||||
|
||||
// imageNotFoundError implements an error returned when an image is not in the docker host.
|
||||
type imageNotFoundError struct {
|
||||
|
|
|
@ -109,7 +109,7 @@ func (cli *Client) sendClientRequest(method, path string, query url.Values, in i
|
|||
|
||||
if err != nil {
|
||||
if utils.IsTimeout(err) || strings.Contains(err.Error(), "connection refused") || strings.Contains(err.Error(), "dial unix") {
|
||||
return serverResp, errConnectionFailed
|
||||
return serverResp, ErrConnectionFailed
|
||||
}
|
||||
|
||||
if cli.Scheme == "http" && strings.Contains(err.Error(), "malformed HTTP response") {
|
||||
|
@ -148,11 +148,7 @@ func encodeData(data interface{}) (*bytes.Buffer, error) {
|
|||
return params, nil
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
func ensureReaderClosed(response *ServerResponse) {
|
||||
=======
|
||||
func ensureReaderClosed(response *serverResponse) {
|
||||
>>>>>>> 9c13063... Implement docker network with standalone client lib.
|
||||
if response != nil && response.body != nil {
|
||||
response.body.Close()
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import (
|
|||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/api"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/client/lib"
|
||||
"github.com/docker/docker/cliconfig"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
"github.com/docker/docker/pkg/jsonmessage"
|
||||
|
@ -263,22 +263,15 @@ func (cli *DockerCli) resizeTty(id string, isExec bool) {
|
|||
// getExitCode perform an inspect on the container. It returns
|
||||
// the running state and the exit code.
|
||||
func getExitCode(cli *DockerCli, containerID string) (bool, int, error) {
|
||||
serverResp, err := cli.call("GET", "/containers/"+containerID+"/json", nil, nil)
|
||||
c, err := cli.client.ContainerInspect(containerID)
|
||||
if err != nil {
|
||||
// If we can't connect, then the daemon probably died.
|
||||
if err != errConnectionFailed {
|
||||
if err != lib.ErrConnectionFailed {
|
||||
return false, -1, err
|
||||
}
|
||||
return false, -1, nil
|
||||
}
|
||||
|
||||
defer serverResp.body.Close()
|
||||
|
||||
var c types.ContainerJSON
|
||||
if err := json.NewDecoder(serverResp.body).Decode(&c); err != nil {
|
||||
return false, -1, err
|
||||
}
|
||||
|
||||
return c.State.Running, c.State.ExitCode, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue