{"record":{"id":"258e6be75ac864f0","repo":"GoogleContainerTools/skaffold","slug":"unable-to-remove-container-w","errorCode":null,"errorMessage":"unable to remove container: %w","messagePattern":"unable to remove container: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/skaffold/docker/image.go","lineNumber":777,"sourceCode":"}\n\nfunc (l *localDaemon) Stop(ctx context.Context, id string, stopTimeout *time.Duration) error {\n\tvar so client.ContainerStopOptions\n\tif stopTimeout != nil {\n\t\tso.Timeout = util.Ptr[int](int(stopTimeout.Seconds()))\n\t}\n\tif _, err := l.apiClient.ContainerStop(ctx, id, so); err != nil {\n\t\tlog.Entry(ctx).Debugf(\"unable to stop running container: %s\", err.Error())\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\nfunc (l *localDaemon) Remove(ctx context.Context, id string) error {\n\tif _, err := l.apiClient.ContainerRemove(ctx, id, client.ContainerRemoveOptions{}); err != nil {\n\t\tlog.Entry(ctx).Debugf(\"unable to remove container: %s\", err.Error())\n\t\treturn fmt.Errorf(\"unable to remove container: %w\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":759,"sourceCodeEnd":782,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/docker/image.go#L759-L782","documentation":"localDaemon.Remove calls apiClient.ContainerRemove to delete a container by id. On failure it logs a debug line and returns \"unable to remove container: %w\" with the daemon error preserved. This is used during skaffold cleanup of port-forward or debug containers.","triggerScenarios":"Calling Remove(ctx, id) when ContainerRemove fails: no such container (already removed), the container is running without a force option (conflict), or the daemon is unreachable.","commonSituations":"Container already exited and auto-removed (race with --rm), attempting cleanup of a still-running container without Force, stale container id from a previous session, Docker daemon restarting during cleanup.","solutions":["Treat 'no such container' as success — check if errdefs.IsNotFound and ignore, since the goal state is already met.","Pass client.ContainerRemoveOptions{Force: true} to remove running containers.","Verify the container id is current (`docker ps -a`) — stale ids from previous runs fail.","Check `docker info` if the daemon itself seems down."],"exampleFix":"// before\nclient.ContainerRemoveOptions{}\n// after\nclient.ContainerRemoveOptions{Force: true, RemoveVolumes: true}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isNotFound(err error) bool { var nf errdefs.NotFoundError; return errors.As(err, &nf) || strings.Contains(err.Error(), \"No such container\") }","tryCatchPattern":"err := daemon.Remove(ctx, id)\nif err != nil {\n    if isNotFound(err) { return nil } // already gone — desired end state\n    if strings.Contains(err.Error(), \"unable to remove container\") { return fmt.Errorf(\"container %s: force remove or check daemon: %w\", id, err) }\n    return err\n}","preventionTips":["Ignore not-found errors on cleanup paths — idempotent removal is the goal.","Use Force:true when containers may still be running.","Refresh container ids each run instead of persisting them.","Confirm daemon health before batch cleanup operations."],"tags":["docker","container","cleanup","remove"],"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"}