Skip to content

Commit bda002f

Browse files
authored
Merge pull request #9125 from chrischdi/pr-docker-fix-flaky-containercreate
🐛 CAPD: delete container after failed start to work around port allocation issues
2 parents 9830681 + fb74bf8 commit bda002f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

test/infrastructure/container/docker.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,13 @@ func (d *dockerRuntime) RunContainer(ctx context.Context, runConfig *RunContaine
505505

506506
// Actually start the container
507507
if err := d.dockerClient.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
508-
return errors.Wrapf(err, "error starting container %q", runConfig.Name)
508+
err := errors.Wrapf(err, "error starting container %q", runConfig.Name)
509+
// Delete the container and retry later on. This helps getting around the race
510+
// condition where of hitting "port is already allocated" issues.
511+
if innerErr := d.dockerClient.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true, RemoveVolumes: true}); innerErr != nil {
512+
return errors.Wrapf(innerErr, "error removing container after failed start: %s", err)
513+
}
514+
return err
509515
}
510516

511517
if output != nil {

0 commit comments

Comments
 (0)