Skip to content

#13178 fix(stacks): allow force removal of stack records when undeploy fails - #13179

Open
cassova wants to merge 1 commit into
portainer:developfrom
cassova:fix13178-force-stack-removal
Open

cassova wants to merge 1 commit into
portainer:developfrom
cassova:fix13178-force-stack-removal

Conversation

@cassova

@cassova cassova commented May 17, 2026

Copy link
Copy Markdown

closes #13178

Summary

When the Docker daemon is unreachable from the Portainer container (e.g. the socket is not mounted), compose down fails — and because that failure also blocks DataStore.Stack().Delete(), the broken stack becomes undeletable through the UI. The user is stuck with a stack record that points to nothing and cannot be cleaned up without fixing socket connectivity first.

This change adds a force=true query parameter to DELETE /stacks/{id} that, when set, proceeds with the Portainer-side cleanup (DB record, resource control, project files) even if the underlying undeploy step returns an error. Default behavior is unchanged: without force, the existing 500 response and record-preserved behavior is identical to today.

Why an explicit opt-in

Silently force-deleting on any docker failure could leak running containers — the daemon may have been only briefly unavailable, in which case unstop'd containers would remain after the Portainer record is gone. Surfacing the choice as a query parameter lets the caller accept that risk only when they need to.

Changes

  • api/http/handler/stacks/stack_delete.go: read force query parameter; on undeploy error, log a warning and continue with record/file cleanup when force=true. Swagger annotation updated.
  • api/http/handler/stacks/stack_delete_test.go: new tests covering the three cases (success, failure without force = 500 + record retained, failure with force = 204 + record removed).

Follow-up (not in this PR)

The frontend currently has no way to send force=true. A small UI follow-up to expose this as a confirmation option in the stack delete flow would make sense once the API shape is settled — happy to submit that as a separate PR after this one is reviewed.

Test plan

  • go test ./api/http/handler/stacks/... passes locally
  • go vet ./api/http/handler/stacks/... clean
  • go build ./... clean
  • Manual verification against a Portainer instance with the docker socket intentionally unmounted

…n undeploy fails

When the Docker daemon is unreachable, compose down fails and the stack
record becomes undeletable through the UI, leaving the user stuck.

Add a force=true query parameter to DELETE /stacks/{id} that, when set,
proceeds with stack record + file removal even if the underlying
undeploy step fails. Default behavior is unchanged.

The force flag is an explicit opt-in because silently force-deleting on
any docker failure could leak running containers; surfacing the choice
to the caller lets the user accept that risk only when they need to.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot remove stack when Docker daemon is unreachable from Portainer

1 participant