Merge pull request #3267 from fir4tozden/bug-fix/volume-cleaning-should-not-be-performed

[CRITICAL] fix: volume cleaning should not be performed
This commit is contained in:
Mauricio Siu
2025-12-19 23:10:31 -06:00
committed by GitHub

View File

@@ -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,48 @@ 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/3267
*/
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) as [
keyof typeof cleanupCommands,
string,
][]) {
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 {
(
Object.entries(cleanupCommands) as [
keyof typeof cleanupCommands,
string,
][]
)
.filter(([key]) => !excludedCleanupAllCommands.includes(key))
.map(async ([, command]) => {
if (serverId) {
await execAsyncRemote(serverId, dockerSafeExec(command));
} else {
await execAsync(dockerSafeExec(command));
}
} catch (error) {}
}),
}),
)
.then((results) => {
const failed = results.filter((r) => r.status === "rejected");