Skip to content

Commit 1b22384

Browse files
authored
Merge pull request #3267 from fir4tozden/bug-fix/volume-cleaning-should-not-be-performed
[CRITICAL] fix: volume cleaning should not be performed
2 parents 6685bd6 + 2b1a3db commit 1b22384

File tree

1 file changed

+33
-9
lines changed
  • packages/server/src/utils/docker

1 file changed

+33
-9
lines changed

packages/server/src/utils/docker/utils.ts

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ echo "Execution completed."`;
174174
const cleanupCommands = {
175175
containers: "docker container prune --force",
176176
images: "docker image prune --all --force",
177+
volumes: "docker volume prune --all --force",
177178
builders: "docker builder prune --all --force",
178179
system: "docker system prune --all --force",
179-
volumes: "docker volume prune --all --force",
180180
};
181181

182182
export const cleanupContainers = async (serverId?: string) => {
@@ -257,24 +257,48 @@ export const cleanupSystem = async (serverId?: string) => {
257257
}
258258
};
259259

260+
/**
261+
* 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.
262+
*
263+
* https://github.com/Dokploy/dokploy/pull/3267
264+
*/
265+
const excludedCleanupAllCommands: (keyof typeof cleanupCommands)[] = [
266+
"volumes",
267+
];
268+
260269
export const cleanupAll = async (serverId?: string) => {
261-
await cleanupContainers(serverId);
262-
await cleanupImages(serverId);
263-
await cleanupBuilders(serverId);
264-
await cleanupSystem(serverId);
270+
for (const [key, command] of Object.entries(cleanupCommands) as [
271+
keyof typeof cleanupCommands,
272+
string,
273+
][]) {
274+
if (excludedCleanupAllCommands.includes(key)) continue;
275+
276+
try {
277+
if (serverId) {
278+
await execAsyncRemote(serverId, dockerSafeExec(command));
279+
} else {
280+
await execAsync(dockerSafeExec(command));
281+
}
282+
} catch {}
283+
}
265284
};
266285

267286
export const cleanupAllBackground = async (serverId?: string) => {
268287
Promise.allSettled(
269-
Object.values(cleanupCommands).map(async (command) => {
270-
try {
288+
(
289+
Object.entries(cleanupCommands) as [
290+
keyof typeof cleanupCommands,
291+
string,
292+
][]
293+
)
294+
.filter(([key]) => !excludedCleanupAllCommands.includes(key))
295+
.map(async ([, command]) => {
271296
if (serverId) {
272297
await execAsyncRemote(serverId, dockerSafeExec(command));
273298
} else {
274299
await execAsync(dockerSafeExec(command));
275300
}
276-
} catch (error) {}
277-
}),
301+
}),
278302
)
279303
.then((results) => {
280304
const failed = results.filter((r) => r.status === "rejected");

0 commit comments

Comments
 (0)