{"record":{"id":"93d399364cde4e88","repo":"louislam/dockge","slug":"failed-to-delete-please-check-the-terminal-output","errorCode":null,"errorMessage":"Failed to delete, please check the terminal output for more information.","messagePattern":"Failed to delete, please check the terminal output for more information\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"backend/stack.ts","lineNumber":220,"sourceCode":"            fs.lchownSync(dir, uid, gid);\n            fs.chownSync(path.join(dir, this._composeFileName), uid, gid);\n        }\n    }\n\n    async deploy(socket : DockgeSocket) : Promise<number> {\n        const terminalName = getComposeTerminalName(socket.endpoint, this.name);\n        let exitCode = await Terminal.exec(this.server, socket, terminalName, \"docker\", this.getComposeOptions(\"up\", \"-d\", \"--remove-orphans\"), this.path);\n        if (exitCode !== 0) {\n            throw new Error(\"Failed to deploy, please check the terminal output for more information.\");\n        }\n        return exitCode;\n    }\n\n    async delete(socket: DockgeSocket) : Promise<number> {\n        const terminalName = getComposeTerminalName(socket.endpoint, this.name);\n        let exitCode = await Terminal.exec(this.server, socket, terminalName, \"docker\", this.getComposeOptions(\"down\", \"--remove-orphans\"), this.path);\n        if (exitCode !== 0) {\n            throw new Error(\"Failed to delete, please check the terminal output for more information.\");\n        }\n\n        // Remove the stack folder\n        await fsAsync.rm(this.path, {\n            recursive: true,\n            force: true\n        });\n\n        return exitCode;\n    }\n\n    async updateStatus() {\n        let statusList = await Stack.getStatusList();\n        let status = statusList.get(this.name);\n\n        if (status) {\n            this._status = status;\n        } else {","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/louislam/dockge/blob/f809ae192b571944ad773e9866d3e67064ae8043/backend/stack.ts#L202-L238","documentation":"Stack.delete() runs 'docker compose down --remove-orphans'; a non-zero exit code throws this Error and the stack folder is NOT removed (the fsAsync.rm happens only after success). Actual cause is visible in the compose terminal.","triggerScenarios":"docker compose down exits non-zero: compose.yaml already deleted/edited so project name or services can't be resolved, Docker daemon error, orphan-network removal failure, containers in a stuck state.","commonSituations":"User edited compose.yaml (renamed project/services) then deleted — down can't find original resources; daemon restarting/unreachable; leftover networks with 'down' failing on external network marked external.","solutions":["Read the compose terminal output in Dockge for the docker error","Ensure compose.yaml still matches the running project before deleting (don't empty it first)","Run 'docker compose down --remove-orphans' manually in the stack dir to diagnose","If containers are stuck, 'docker rm -f' them / restart Docker, then delete again","If the folder remains after a partial failure, remove it manually after confirming containers are gone"],"exampleFix":"// before\nawait stack.delete(socket);\n// after\ntry {\n    await stack.delete(socket);\n} catch (e) {\n    log.error(\"delete\", `Compose down failed; stack folder for '${stack.name}' was kept. Fix compose.yaml or remove containers manually.`);\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"import { existsSync, readFileSync } from \"fs\";\nfunction canDelete(dir: string): boolean {\n    return existsSync(dir) && existsSync(dir + \"/compose.yaml\")\n        && readFileSync(dir + \"/compose.yaml\", \"utf8\").trim().length > 0;\n}\nif (!canDelete(stack.path)) {\n    throw new Error(\"compose.yaml missing/empty — down would fail; restore it before deleting\");\n}\nawait stack.delete(socket);","typeGuard":"function isDeletable(stack: Stack): boolean {\n    return typeof stack.name === \"string\" && stack.name.length > 0 && !!stack.composeYAML;\n}","tryCatchPattern":"try {\n    await stack.delete(socket);\n} catch (e) {\n    log.error(\"delete\", \"Compose down failed — stack folder retained; fix compose.yaml or remove containers manually, then retry\");\n    throw e;\n}","preventionTips":["Never empty or rename compose.yaml right before deleting a stack","Confirm docker daemon is healthy before teardown operations","Clean up orphaned networks/containers periodically","If down keeps failing, remove containers with docker rm -f first"],"tags":["docker","docker-compose","deletion","terminal"],"backgroundTag":"docker-compose-down-failed","analyzedSha":"f809ae192b571944ad773e9866d3e67064ae8043","analyzedAt":"2026-08-31T19:13:50.919Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}