@@ -174,9 +174,9 @@ echo "Execution completed."`;
174174const 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
182182export 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+
260269export 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
267286export 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