{"record":{"id":"1c3708c64744605f","repo":"GoogleContainerTools/skaffold","slug":"failed-to-remove-old-container-s-for-image-s-w-1c3708","errorCode":null,"errorMessage":"failed to remove old container %s for image %s: %w","messagePattern":"failed to remove old container (.+?) for image (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/verify/docker/verify.go","lineNumber":209,"sourceCode":"\t\t\t})\n\t\t}\n\t\ts.Go(func() error {\n\t\t\treturn v.createAndRunContainer(ctx, out, na, *testCase)\n\t\t})\n\t}\n\tv.TrackBuildArtifacts(builds)\n\treturn s.Wait()\n}\n\n// createAndRunContainer creates and runs a container in the local docker daemon from the specified verify image.\nfunc (v *Verifier) createAndRunContainer(ctx context.Context, out io.Writer, artifact graph.Artifact, tc latest.VerifyTestCase) error {\n\tout, ctx = output.WithEventContext(ctx, out, constants.Verify, tc.Name)\n\n\tif container, found := v.tracker.ContainerForImage(artifact.ImageName); found {\n\t\tolog.Entry(ctx).Debugf(\"removing old container %s for image %s\", container.ID, artifact.ImageName)\n\t\tv.client.Stop(ctx, container.ID, nil)\n\t\tif err := v.client.Remove(ctx, container.ID); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to remove old container %s for image %s: %w\", container.ID, artifact.ImageName, err)\n\t\t}\n\t\tv.portManager.RelinquishPorts(container.Name)\n\t}\n\tcontainerCfg, err := v.containerConfigFromImage(ctx, artifact.Tag)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// user has set the container Entrypoint, use user value\n\tif len(tc.Container.Command) != 0 {\n\t\tcontainerCfg.Entrypoint = tc.Container.Command\n\t}\n\n\t// user has set the container Cmd values, use user value\n\tif len(tc.Container.Args) != 0 {\n\t\tcontainerCfg.Cmd = tc.Container.Args\n\t}\n","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/verify/docker/verify.go#L191-L227","documentation":"Skaffold's Docker-based verifier wraps an underlying Docker client error encountered while removing a stale container that was previously started for the same verify test's image. Before starting a new container, it stops and deletes the old one so ports and names are free; if the Docker API Remove call fails, this error surfaces the container ID and image name along with the wrapped cause.","triggerScenarios":"createAndRunContainer finds an existing tracked container for the artifact image (v.tracker.ContainerForImage) and v.client.Remove(ctx, container.ID) returns an error, e.g. because the container was already removed externally, is in a state that forbids removal, or the Docker daemon is unreachable/returning 500s.","commonSituations":"The container was deleted by another process or `docker rm` while a verify run was in flight; a race where two skaffold verify invocations target the same image; Docker daemon restarting or resource issues (device busy, dependent containers); stale tracker state pointing at a removed container ID.","solutions":["Check the wrapped cause (`docker ps -a`, `docker logs`) to see why removal failed and fix the daemon-level issue first","Remove the stale container manually: `docker rm -f <containerID>` then re-run verify","Restart the Docker daemon if it is unresponsive or returning internal errors","Avoid running concurrent skaffold verify/deploy runs against the same image names","Update Docker/Skaffold if a known API incompatibility causes removal failures"],"exampleFix":"// before: stale tracked container blocks verify\n$ docker rm -f <oldContainerID>\n$ skaffold verify\n// after: verify proceeds, creating a fresh container for the image","handlingStrategy":"validation","validationCode":"if c, found := tracker.ContainerForImage(artifact.ImageName); found {\n    if err := client.Remove(ctx, c.ID); err != nil {\n        // fall back to force removal / manual `docker rm -f <id>`\n        _ = client.Stop(ctx, c.ID, nil)\n    }\n}","typeGuard":"func containerExists(ctx context.Context, c ContainerClient, id string) bool {\n    _, err := c.Inspect(ctx, id)\n    return err == nil\n}","tryCatchPattern":"out, err := verifier.Verify(ctx, out)\nif err != nil && strings.Contains(err.Error(), \"failed to remove old container\") {\n    // inspect wrapped error, clean up manually, retry once\n}","preventionTips":["Don't run concurrent skaffold verify runs for the same image","Prune stale containers (`docker container prune`) before long-running sessions","Check `docker ps -a` and the wrapped error cause before re-running","Keep Docker daemon healthy and up to date"],"tags":["docker","container-lifecycle","verify"],"backgroundTag":"docker-container-remove-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}