{"record":{"id":"e80ddd1b814e9f90","repo":"GoogleContainerTools/skaffold","slug":"cleaning-up-deployed-container","errorCode":null,"errorMessage":"cleaning up deployed container","messagePattern":"cleaning up deployed container","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/deploy/docker/deploy.go","lineNumber":366,"sourceCode":"\treturn currentName\n}\n\nfunc (d *Deployer) Dependencies() ([]string, error) {\n\t// noop since there is no deploy config\n\treturn nil, nil\n}\n\nfunc (d *Deployer) Cleanup(ctx context.Context, out io.Writer, dryRun bool, _ manifest.ManifestListByConfig) error {\n\tif dryRun {\n\t\tfor _, container := range d.tracker.DeployedContainers() {\n\t\t\toutput.Yellow.Fprintln(out, container.ID)\n\t\t}\n\t\treturn nil\n\t}\n\tfor _, container := range d.tracker.DeployedContainers() {\n\t\tif err := d.client.Delete(ctx, out, container.ID); err != nil {\n\t\t\t// TODO(nkubala): replace with actionable error\n\t\t\treturn errors.Wrap(err, \"cleaning up deployed container\")\n\t\t}\n\t\td.portManager.RelinquishPorts(container.ID)\n\t}\n\n\tfor _, m := range d.debugger.SupportMounts() {\n\t\tif err := d.client.VolumeRemove(ctx, m.Source); err != nil {\n\t\t\treturn errors.Wrap(err, \"cleaning up debug support volume\")\n\t\t}\n\t}\n\n\tif err := d.client.NetworkRemove(ctx, d.network); d.networkDeployed && err != nil {\n\t\treturn errors.Wrap(err, \"cleaning up skaffold created network\")\n\t}\n\n\treturn d.cleanPreviousDeployments(ctx)\n}\n\nfunc (d *Deployer) cleanPreviousDeployments(ctx context.Context) error {","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/deploy/docker/deploy.go#L348-L384","documentation":"During Cleanup, the docker deployer deletes every container recorded in its tracker via d.client.Delete. If the daemon fails to remove one (missing, in use, daemon error), the error is wrapped with \"cleaning up deployed container\" and cleanup aborts, leaving remaining resources behind.","triggerScenarios":"Deployer.Cleanup iterates d.tracker.DeployedContainers() and d.client.Delete(ctx, out, container.ID) returns an error — container already gone (404 on some code paths), stop timeout, or daemon unreachable.","commonSituations":"Container manually removed with `docker rm` before `skaffold delete`; container stuck in a non-stoppable state after a daemon crash; Docker Desktop/colima shut down before cleanup; stale tracker state from a previous failed run.","solutions":["Run `skaffold delete` again — often the remaining containers then clean or are already gone","Manually remove leftovers: `docker rm -f <container-id>` (IDs are in the tracker/daemon)","Restart the Docker daemon and re-run cleanup if the daemon was down","Wipe all skaffold-tagged resources: `docker ps -aq --filter label=<skaffold-label> | xargs docker rm -f`","Check the wrapped inner error: a 404 usually means the container was already deleted and is safe to ignore"],"exampleFix":"// before\nerror: cleaning up deployed container: Error response from daemon: removal of container ... is already in progress\n// after\n$ docker rm -f <container-id>\n$ skaffold delete  # now completes","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"if err := deployer.Cleanup(ctx, out); err != nil {\n  if strings.Contains(err.Error(), \"cleaning up deployed container\") {\n    log.Printf(\"partial cleanup: %v; continuing with manual removal\", err)\n    exec.Command(\"sh\", \"-c\", \"docker ps -aq --filter label=skaffold.dev/... | xargs -r docker rm -f\").Run()\n  }\n  return err\n}","preventionTips":["Never `docker rm` skaffold-managed containers manually before `skaffold delete`","Keep the daemon running until cleanup completes","Re-run `skaffold delete` after any failed cleanup","Treat 404 inner errors as already-cleaned and non-fatal"],"tags":["docker","cleanup","container-delete"],"backgroundTag":"cleanup-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"}