Skip to content

fix: workaround for moby/moby#50133 when reusing container #3197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1364,11 +1364,19 @@ func (p *DockerProvider) ReuseOrCreateContainer(ctx context.Context, req Contain
lifecycleHooks: []ContainerLifecycleHooks{combineContainerHooks(defaultHooks, req.LifecycleHooks)},
}

// Workaround for https://github.com/moby/moby/issues/50133.
// /containers/{id}/json API endpoint of Docker Engine takes data about container from master (not replica) database
// which is synchronized with container state after call of /containers/{id}/stop API endpoint.
dcState, err := dc.State(ctx)
if err != nil {
return nil, fmt.Errorf("docker container state: %w", err)
}

// If a container was stopped programmatically, we want to ensure the container
// is running again, but only if it is not paused, as it's not possible to start
// a paused container. The Docker Engine returns the "cannot start a paused container,
// try unpause instead" error.
switch c.State {
switch dcState.Status {
case "running":
// cannot re-start a running container, but we still need
// to call the startup hooks.
Expand Down
Loading