Skip to content

Modern Docker Management, Designed for Everyone

fix: volumes not removed when selected on container removal dialog

Kyle Mendellbb928fe72af2
diff --git a/backend/internal/services/container_service.go b/backend/internal/services/container_service.go
index 2af24e05a..48a03bd71 100644
--- a/backend/internal/services/container_service.go
+++ b/backend/internal/services/container_service.go
@@ -129,6 +129,20 @@ func (s *ContainerService) DeleteContainer(ctx context.Context, containerID stri
}
defer dockerClient.Close()
+ // Get container mounts before deletion if we need to remove volumes
+ var volumesToRemove []string
+ if removeVolumes {
+ containerJSON, inspectErr := dockerClient.ContainerInspect(ctx, containerID)
+ if inspectErr == nil {
+ for _, mount := range containerJSON.Mounts {
+ // Only collect named volumes (not bind mounts or tmpfs)
+ if mount.Type == "volume" && mount.Name != "" {
+ volumesToRemove = append(volumesToRemove, mount.Name)
+ }
+ }
+ }
+ }
+
err = dockerClient.ContainerRemove(ctx, containerID, container.RemoveOptions{
Force: force,
RemoveVolumes: removeVolumes,
@@ -139,6 +153,16 @@ func (s *ContainerService) DeleteContainer(ctx context.Context, containerID stri
return fmt.Errorf("failed to delete container: %w", err)
}
+ // Remove named volumes if requested
+ if removeVolumes && len(volumesToRemove) > 0 {
+ for _, volumeName := range volumesToRemove {
+ if removeErr := dockerClient.VolumeRemove(ctx, volumeName, false); removeErr != nil {
+ // Log but don't fail if volume removal fails (might be in use by another container)
+ s.eventService.LogErrorEvent(ctx, models.EventTypeVolumeError, "volume", volumeName, "", user.ID, user.Username, "0", removeErr, models.JSON{"action": "delete", "container": containerID})
+ }
+ }
+ }
+
metadata := models.JSON{
"action": "delete",
"containerId": containerID,
diff --git a/frontend/src/lib/components/action-buttons.svelte b/frontend/src/lib/components/action-buttons.svelte
index 6a1500287..8edaa4380 100644
--- a/frontend/src/lib/components/action-buttons.svelte
+++ b/frontend/src/lib/components/action-buttons.svelte
@@ -159,7 +159,7 @@
handleApiResultWithCallbacks({
result: await tryCatch(
type === 'container'
- ? containerService.deleteContainer(id)
+ ? containerService.deleteContainer(id, { volumes: removeVolumes })
: projectService.destroyProject(id, removeVolumes, removeFiles)
),
message: m.common_action_failed_with_type({