{"record":{"id":"027030ce7c3aea07","repo":"louislam/dockge","slug":"failed-to-restart-service-servicename-please-c","errorCode":null,"errorMessage":"Failed to restart service ${serviceName}, please check logs for more information.","messagePattern":"Failed to restart service (.+?), please check logs for more information\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"backend/stack.ts","lineNumber":578,"sourceCode":"\n        return exitCode;\n    }\n\n    async stopService(socket: DockgeSocket, serviceName: string): Promise<number> {\n        const terminalName = getComposeTerminalName(socket.endpoint, this.name);\n        const exitCode = await Terminal.exec(this.server, socket, terminalName, \"docker\", [ \"compose\", \"stop\", serviceName ], this.path);\n        if (exitCode !== 0) {\n            throw new Error(`Failed to stop service ${serviceName}, please check logs for more information.`);\n        }\n\n        return exitCode;\n    }\n\n    async restartService(socket: DockgeSocket, serviceName: string): Promise<number> {\n        const terminalName = getComposeTerminalName(socket.endpoint, this.name);\n        const exitCode = await Terminal.exec(this.server, socket, terminalName, \"docker\", [ \"compose\", \"restart\", serviceName ], this.path);\n        if (exitCode !== 0) {\n            throw new Error(`Failed to restart service ${serviceName}, please check logs for more information.`);\n        }\n\n        return exitCode;\n    }\n}\n","sourceCodeStart":560,"sourceCodeEnd":584,"githubUrl":"https://github.com/louislam/dockge/blob/f809ae192b571944ad773e9866d3e67064ae8043/backend/stack.ts#L560-L584","documentation":"Stack.restartService() runs `docker compose restart <serviceName>` in the stack directory and throws this error when the command exits non-zero. The message names the service; the root-cause output (daemon errors, unknown service, container create failures) is in the terminal stream.","triggerScenarios":"Calling the restart-service socket action when `docker compose restart <name>` exits non-zero — service not defined in the compose file, no such container running, or docker daemon unavailable.","commonSituations":"Restarting a service whose container was removed (docker compose restart only works on existing containers); compose file edited so the service name no longer matches; docker daemon restart left the container in a bad state.","solutions":["Check the terminal output for the docker restart error","Verify the container exists: `docker compose ps` in the stack directory","If the container was removed, use `docker compose up -d <service>` instead of restart","Confirm the service name against the current compose file and retry"],"exampleFix":"// before\nawait stack.restartService(socket, \"db\"); // container was removed, restart fails\n// after\nif (await serviceContainerExists(stack.path, \"db\")) {\n  await stack.restartService(socket, \"db\");\n} else {\n  await stack.startService(socket, \"db\"); // recreate via up -d\n}","handlingStrategy":"validation","validationCode":"const ps = await exec(`docker compose -f ${stack.path}/compose.yml ps -q ${serviceName}`);\nif (!ps.stdout.trim()) {\n  // container does not exist; use up -d instead of restart\n  await stack.startService(socket, serviceName);\n} else {\n  await stack.restartService(socket, serviceName);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await stack.restartService(socket, serviceName);\n} catch (e) {\n  if (e.message.startsWith(\"Failed to restart service\")) {\n    await stack.startService(socket, serviceName); // fallback: recreate via up -d\n  } else throw e;\n}","preventionTips":["Remember `docker compose restart` requires an existing container — use `up -d` for recreation","Confirm the service name matches the current compose file","Check daemon health after host reboots before restarting services","Prefer restart policies (restart: unless-stopped) over manual restarts where possible"],"tags":["docker","docker-compose","service-restart","exit-code"],"backgroundTag":"docker-compose-service-restart-failed","analyzedSha":"f809ae192b571944ad773e9866d3e67064ae8043","analyzedAt":"2026-08-31T19:13:50.919Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}