Signed-off-by: David Calavera <david.calavera@gmail.com>
| ... | ... |
@@ -1,6 +1,11 @@ |
| 1 | 1 |
package lib |
| 2 | 2 |
|
| 3 |
-import "fmt" |
|
| 3 |
+import ( |
|
| 4 |
+ "errors" |
|
| 5 |
+ "fmt" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+var ErrConnectionFailed = errors.New("Cannot connect to the Docker daemon. Is the docker daemon running on this host?")
|
|
| 4 | 9 |
|
| 5 | 10 |
// imageNotFoundError implements an error returned when an image is not in the docker host. |
| 6 | 11 |
type imageNotFoundError struct {
|
| ... | ... |
@@ -109,7 +109,7 @@ func (cli *Client) sendClientRequest(method, path string, query url.Values, in i |
| 109 | 109 |
|
| 110 | 110 |
if err != nil {
|
| 111 | 111 |
if utils.IsTimeout(err) || strings.Contains(err.Error(), "connection refused") || strings.Contains(err.Error(), "dial unix") {
|
| 112 |
- return serverResp, errConnectionFailed |
|
| 112 |
+ return serverResp, ErrConnectionFailed |
|
| 113 | 113 |
} |
| 114 | 114 |
|
| 115 | 115 |
if cli.Scheme == "http" && strings.Contains(err.Error(), "malformed HTTP response") {
|
| ... | ... |
@@ -148,11 +148,7 @@ func encodeData(data interface{}) (*bytes.Buffer, error) {
|
| 148 | 148 |
return params, nil |
| 149 | 149 |
} |
| 150 | 150 |
|
| 151 |
-<<<<<<< HEAD |
|
| 152 | 151 |
func ensureReaderClosed(response *ServerResponse) {
|
| 153 |
-======= |
|
| 154 |
-func ensureReaderClosed(response *serverResponse) {
|
|
| 155 |
->>>>>>> 9c13063... Implement docker network with standalone client lib. |
|
| 156 | 152 |
if response != nil && response.body != nil {
|
| 157 | 153 |
response.body.Close() |
| 158 | 154 |
} |
| ... | ... |
@@ -19,7 +19,7 @@ import ( |
| 19 | 19 |
|
| 20 | 20 |
"github.com/Sirupsen/logrus" |
| 21 | 21 |
"github.com/docker/docker/api" |
| 22 |
- "github.com/docker/docker/api/types" |
|
| 22 |
+ "github.com/docker/docker/api/client/lib" |
|
| 23 | 23 |
"github.com/docker/docker/cliconfig" |
| 24 | 24 |
"github.com/docker/docker/dockerversion" |
| 25 | 25 |
"github.com/docker/docker/pkg/jsonmessage" |
| ... | ... |
@@ -263,22 +263,15 @@ func (cli *DockerCli) resizeTty(id string, isExec bool) {
|
| 263 | 263 |
// getExitCode perform an inspect on the container. It returns |
| 264 | 264 |
// the running state and the exit code. |
| 265 | 265 |
func getExitCode(cli *DockerCli, containerID string) (bool, int, error) {
|
| 266 |
- serverResp, err := cli.call("GET", "/containers/"+containerID+"/json", nil, nil)
|
|
| 266 |
+ c, err := cli.client.ContainerInspect(containerID) |
|
| 267 | 267 |
if err != nil {
|
| 268 | 268 |
// If we can't connect, then the daemon probably died. |
| 269 |
- if err != errConnectionFailed {
|
|
| 269 |
+ if err != lib.ErrConnectionFailed {
|
|
| 270 | 270 |
return false, -1, err |
| 271 | 271 |
} |
| 272 | 272 |
return false, -1, nil |
| 273 | 273 |
} |
| 274 | 274 |
|
| 275 |
- defer serverResp.body.Close() |
|
| 276 |
- |
|
| 277 |
- var c types.ContainerJSON |
|
| 278 |
- if err := json.NewDecoder(serverResp.body).Decode(&c); err != nil {
|
|
| 279 |
- return false, -1, err |
|
| 280 |
- } |
|
| 281 |
- |
|
| 282 | 275 |
return c.State.Running, c.State.ExitCode, nil |
| 283 | 276 |
} |
| 284 | 277 |
|