Skip to content

Commit 9533bca

Browse files
authored
fix: workaround for moby/moby#50133 when reusing container in testcontainers.GenericContainer. (testcontainers#3197)
Signed-off-by: Marat Abrarov <abrarov@gmail.com>
1 parent d72fc00 commit 9533bca

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

docker.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,11 +1364,19 @@ func (p *DockerProvider) ReuseOrCreateContainer(ctx context.Context, req Contain
13641364
lifecycleHooks: []ContainerLifecycleHooks{combineContainerHooks(defaultHooks, req.LifecycleHooks)},
13651365
}
13661366

1367+
// Workaround for https://github.com/moby/moby/issues/50133.
1368+
// /containers/{id}/json API endpoint of Docker Engine takes data about container from master (not replica) database
1369+
// which is synchronized with container state after call of /containers/{id}/stop API endpoint.
1370+
dcState, err := dc.State(ctx)
1371+
if err != nil {
1372+
return nil, fmt.Errorf("docker container state: %w", err)
1373+
}
1374+
13671375
// If a container was stopped programmatically, we want to ensure the container
13681376
// is running again, but only if it is not paused, as it's not possible to start
13691377
// a paused container. The Docker Engine returns the "cannot start a paused container,
13701378
// try unpause instead" error.
1371-
switch c.State {
1379+
switch dcState.Status {
13721380
case "running":
13731381
// cannot re-start a running container, but we still need
13741382
// to call the startup hooks.

0 commit comments

Comments
 (0)