From ed4ddc5536dd84f1bac70b93401b9d23b5ec4c5e Mon Sep 17 00:00:00 2001 From: clawbot Date: Sun, 8 Feb 2026 12:02:56 -0800 Subject: [PATCH] fix: clean up Docker container when deleting an app (closes #2) --- internal/handlers/app.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/internal/handlers/app.go b/internal/handlers/app.go index 2887139..f5893f2 100644 --- a/internal/handlers/app.go +++ b/internal/handlers/app.go @@ -267,6 +267,29 @@ func (h *Handlers) HandleAppDelete() http.HandlerFunc { return } + // Stop and remove the Docker container before deleting the DB record + containerInfo, containerErr := h.docker.FindContainerByAppID(request.Context(), appID) + if containerErr == nil && containerInfo != nil { + if containerInfo.Running { + stopErr := h.docker.StopContainer(request.Context(), containerInfo.ID) + if stopErr != nil { + h.log.Error("failed to stop container during app deletion", + "error", stopErr, "app", application.Name, + "container", containerInfo.ID) + } + } + + removeErr := h.docker.RemoveContainer(request.Context(), containerInfo.ID, true) + if removeErr != nil { + h.log.Error("failed to remove container during app deletion", + "error", removeErr, "app", application.Name, + "container", containerInfo.ID) + } else { + h.log.Info("removed container during app deletion", + "app", application.Name, "container", containerInfo.ID) + } + } + deleteErr := application.Delete(request.Context()) if deleteErr != nil { h.log.Error("failed to delete app", "error", deleteErr)