@@ -18,12 +18,12 @@ import (
18
18
"syscall"
19
19
"time"
20
20
21
+ dockertypes "github.com/docker/docker/api/types"
22
+ dockercontainer "github.com/docker/docker/api/types/container"
23
+ dockernetwork "github.com/docker/docker/api/types/network"
24
+ dockerapi "github.com/docker/docker/client"
21
25
dockermessage "github.com/docker/docker/pkg/jsonmessage"
22
26
dockerstdcopy "github.com/docker/docker/pkg/stdcopy"
23
- dockerapi "github.com/docker/engine-api/client"
24
- dockertypes "github.com/docker/engine-api/types"
25
- dockercontainer "github.com/docker/engine-api/types/container"
26
- dockernetwork "github.com/docker/engine-api/types/network"
27
27
"github.com/docker/go-connections/tlsconfig"
28
28
"golang.org/x/net/context"
29
29
@@ -142,19 +142,19 @@ type Docker interface {
142
142
// Client contains all methods used when interacting directly with docker engine-api
143
143
type Client interface {
144
144
ContainerAttach (ctx context.Context , container string , options dockertypes.ContainerAttachOptions ) (dockertypes.HijackedResponse , error )
145
- ContainerCommit (ctx context.Context , container string , options dockertypes.ContainerCommitOptions ) (dockertypes.ContainerCommitResponse , error )
146
- ContainerCreate (ctx context.Context , config * dockercontainer.Config , hostConfig * dockercontainer.HostConfig , networkingConfig * dockernetwork.NetworkingConfig , containerName string ) (dockertypes. ContainerCreateResponse , error )
147
- ContainerInspect (ctx context.Context , containerID string ) (dockertypes.ContainerJSON , error )
148
- ContainerRemove (ctx context.Context , containerID string , options dockertypes.ContainerRemoveOptions ) error
149
- ContainerStart (ctx context.Context , containerID string ) error
150
- ContainerKill (ctx context.Context , containerID , signal string ) error
151
- ContainerWait (ctx context.Context , containerID string ) (int , error )
145
+ ContainerCommit (ctx context.Context , container string , options dockertypes.ContainerCommitOptions ) (dockertypes.IDResponse , error )
146
+ ContainerCreate (ctx context.Context , config * dockercontainer.Config , hostConfig * dockercontainer.HostConfig , networkingConfig * dockernetwork.NetworkingConfig , containerName string ) (dockercontainer. ContainerCreateCreatedBody , error )
147
+ ContainerInspect (ctx context.Context , container string ) (dockertypes.ContainerJSON , error )
148
+ ContainerRemove (ctx context.Context , container string , options dockertypes.ContainerRemoveOptions ) error
149
+ ContainerStart (ctx context.Context , container string , options dockertypes. ContainerStartOptions ) error
150
+ ContainerKill (ctx context.Context , container , signal string ) error
151
+ ContainerWait (ctx context.Context , container string , condition dockercontainer. WaitCondition ) (<- chan dockercontainer. ContainerWaitOKBody , <- chan error )
152
152
CopyToContainer (ctx context.Context , container , path string , content io.Reader , opts dockertypes.CopyToContainerOptions ) error
153
153
CopyFromContainer (ctx context.Context , container , srcPath string ) (io.ReadCloser , dockertypes.ContainerPathStat , error )
154
154
ImageBuild (ctx context.Context , buildContext io.Reader , options dockertypes.ImageBuildOptions ) (dockertypes.ImageBuildResponse , error )
155
- ImageInspectWithRaw (ctx context.Context , imageID string , getSize bool ) (dockertypes.ImageInspect , []byte , error )
155
+ ImageInspectWithRaw (ctx context.Context , image string ) (dockertypes.ImageInspect , []byte , error )
156
156
ImagePull (ctx context.Context , ref string , options dockertypes.ImagePullOptions ) (io.ReadCloser , error )
157
- ImageRemove (ctx context.Context , imageID string , options dockertypes.ImageRemoveOptions ) ([]dockertypes.ImageDelete , error )
157
+ ImageRemove (ctx context.Context , image string , options dockertypes.ImageRemoveOptions ) ([]dockertypes.ImageDeleteResponseItem , error )
158
158
ServerVersion (ctx context.Context ) (dockertypes.Version , error )
159
159
}
160
160
@@ -167,7 +167,7 @@ type stiDocker struct {
167
167
func (d stiDocker ) InspectImage (name string ) (* dockertypes.ImageInspect , error ) {
168
168
ctx , cancel := getDefaultContext ()
169
169
defer cancel ()
170
- resp , _ , err := d .client .ImageInspectWithRaw (ctx , name , false )
170
+ resp , _ , err := d .client .ImageInspectWithRaw (ctx , name )
171
171
if err != nil {
172
172
return nil , err
173
173
}
@@ -819,7 +819,7 @@ func determineCommandBaseDir(opts RunContainerOptions, imageMetadata *api.Image,
819
819
}
820
820
821
821
// dumpContainerInfo dumps information about a running container (port/IP/etc).
822
- func dumpContainerInfo (container dockertypes. ContainerCreateResponse , d * stiDocker , image string ) {
822
+ func dumpContainerInfo (container dockercontainer. ContainerCreateCreatedBody , d * stiDocker , image string ) {
823
823
ctx , cancel := getDefaultContext ()
824
824
defer cancel ()
825
825
@@ -1024,7 +1024,7 @@ func (d *stiDocker) RunContainer(opts RunContainerOptions) error {
1024
1024
glog .V (2 ).Infof ("Starting container %q ..." , container .ID )
1025
1025
ctx , cancel = getDefaultContext ()
1026
1026
defer cancel ()
1027
- err = d .client .ContainerStart (ctx , container .ID )
1027
+ err = d .client .ContainerStart (ctx , container .ID , dockertypes. ContainerStartOptions {} )
1028
1028
if err != nil {
1029
1029
return err
1030
1030
}
@@ -1053,18 +1053,20 @@ func (d *stiDocker) RunContainer(opts RunContainerOptions) error {
1053
1053
// Return an error if the exit code of the container is
1054
1054
// non-zero.
1055
1055
glog .V (4 ).Infof ("Waiting for container %q to stop ..." , container .ID )
1056
- exitCode , err := d .client .ContainerWait (context .Background (), container .ID )
1057
- if err != nil {
1058
- return fmt .Errorf ("waiting for container %q to stop: %v" , container .ID , err )
1059
- }
1060
- if exitCode != 0 {
1061
- var output string
1062
- json , _ := d .client .ContainerInspect (ctx , container .ID )
1063
- if err == nil && json .ContainerJSONBase != nil && json .ContainerJSONBase .State != nil {
1064
- state := json .ContainerJSONBase .State
1065
- output = fmt .Sprintf ("Status: %s, Error: %s, OOMKilled: %v, Dead: %v" , state .Status , state .Error , state .OOMKilled , state .Dead )
1056
+ waitC , errC := d .client .ContainerWait (context .Background (), container .ID , dockercontainer .WaitConditionNextExit )
1057
+ select {
1058
+ case result := <- waitC :
1059
+ if result .StatusCode != 0 {
1060
+ var output string
1061
+ json , _ := d .client .ContainerInspect (ctx , container .ID )
1062
+ if err == nil && json .ContainerJSONBase != nil && json .ContainerJSONBase .State != nil {
1063
+ state := json .ContainerJSONBase .State
1064
+ output = fmt .Sprintf ("Status: %s, Error: %s, OOMKilled: %v, Dead: %v" , state .Status , state .Error , state .OOMKilled , state .Dead )
1065
+ }
1066
+ return s2ierr .NewContainerError (container .ID , int (result .StatusCode ), output )
1066
1067
}
1067
- return s2ierr .NewContainerError (container .ID , exitCode , output )
1068
+ case err := <- errC :
1069
+ return fmt .Errorf ("waiting for container %q to stop: %v" , container .ID , err )
1068
1070
}
1069
1071
1070
1072
// OnStart must be done before we move on.
0 commit comments