From 19a7a80d43cd99c9f1a96da6fe37122bb599094f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D1=84=D1=8B=D1=80=D0=B0=D1=82=20=D1=91=D0=B7=D0=B4=D1=8D?= =?UTF-8?q?=D0=BD?= <31664778+fir4tozden@users.noreply.github.com> Date: Sun, 14 Dec 2025 08:06:55 +0300 Subject: [PATCH] [BUG] fix: volume cleaning should not be performed --- packages/server/src/utils/docker/utils.ts | 44 +++++++++++++++-------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/packages/server/src/utils/docker/utils.ts b/packages/server/src/utils/docker/utils.ts index d674a8840..a58ad441c 100644 --- a/packages/server/src/utils/docker/utils.ts +++ b/packages/server/src/utils/docker/utils.ts @@ -174,9 +174,9 @@ echo "Execution completed."`; const cleanupCommands = { containers: "docker container prune --force", images: "docker image prune --all --force", + volumes: "docker volume prune --all --force", builders: "docker builder prune --all --force", system: "docker system prune --all --force", - volumes: "docker volume prune --all --force", }; export const cleanupContainers = async (serverId?: string) => { @@ -257,24 +257,40 @@ export const cleanupSystem = async (serverId?: string) => { } }; +/** + * Volume cleanup should always be performed manually by the user. The reason is that during automatic cleanup, a volume may be deleted due to a stopped container, which is a dangerous situation. + * + * https://github.com/Dokploy/dokploy/pull/3266 + */ +const excludedCleanupAllCommands: (keyof typeof cleanupCommands)[] = ['volumes']; + export const cleanupAll = async (serverId?: string) => { - await cleanupContainers(serverId); - await cleanupImages(serverId); - await cleanupBuilders(serverId); - await cleanupSystem(serverId); + for (const [key, command] of Object.entries(cleanupCommands)) { + if (excludedCleanupAllCommands.includes(key)) continue; + + try { + if (serverId) { + await execAsyncRemote(serverId, dockerSafeExec(command)); + } else { + await execAsync(dockerSafeExec(command)); + } + } catch {} + } }; export const cleanupAllBackground = async (serverId?: string) => { Promise.allSettled( - Object.values(cleanupCommands).map(async (command) => { - try { - if (serverId) { - await execAsyncRemote(serverId, dockerSafeExec(command)); - } else { - await execAsync(dockerSafeExec(command)); - } - } catch (error) {} - }), + Object.entries(cleanupCommands) + .filter(([key]) => !excludedCleanupAllCommands.includes(key)) + .map(async ([, command]) => { + try { + if (serverId) { + await execAsyncRemote(serverId, dockerSafeExec(command)); + } else { + await execAsync(dockerSafeExec(command)); + } + } catch {} + }) ) .then((results) => { const failed = results.filter((r) => r.status === "rejected");