Skip to content

Commit

Permalink
Merge pull request #9125 from chrischdi/pr-docker-fix-flaky-container…
Browse files Browse the repository at this point in the history
…create

🐛 CAPD: delete container after failed start to work around port allocation issues
  • Loading branch information
k8s-ci-robot committed Aug 7, 2023
2 parents 9830681 + fb74bf8 commit bda002f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/infrastructure/container/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,13 @@ func (d *dockerRuntime) RunContainer(ctx context.Context, runConfig *RunContaine

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

if output != nil {
Expand Down

0 comments on commit bda002f

Please sign in to comment.