mirror of https://github.com/docker/cli.git
Fix hang when container fails to start
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
(cherry picked from commit 31644d5ea7
)
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
This commit is contained in:
parent
4cf5afaefa
commit
ccea7d8a30
|
@ -186,7 +186,11 @@ func runContainer(ctx context.Context, dockerCli command.Cli, runOpts *runOption
|
|||
defer closeFn()
|
||||
}
|
||||
|
||||
statusChan := waitExitOrRemoved(ctx, apiClient, containerID, copts.autoRemove)
|
||||
// New context here because we don't to cancel waiting on container exit/remove
|
||||
// when we cancel attach, etc.
|
||||
statusCtx, cancelStatusCtx := context.WithCancel(context.WithoutCancel(ctx))
|
||||
defer cancelStatusCtx()
|
||||
statusChan := waitExitOrRemoved(statusCtx, apiClient, containerID, copts.autoRemove)
|
||||
|
||||
// start the container
|
||||
if err := apiClient.ContainerStart(ctx, containerID, container.StartOptions{}); err != nil {
|
||||
|
|
|
@ -36,6 +36,7 @@ func waitExitOrRemoved(ctx context.Context, apiClient client.APIClient, containe
|
|||
|
||||
statusC := make(chan int)
|
||||
go func() {
|
||||
defer close(statusC)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue