diff --git a/backend/routes/admin.js b/backend/routes/admin.js index 841120e..bdcbbd0 100644 --- a/backend/routes/admin.js +++ b/backend/routes/admin.js @@ -1178,10 +1178,11 @@ async function getRunningServer() { // 컨테이너 상태 확인 async function getContainerStatus(serverPath) { try { + const fullPath = path.join(SERVER_BASE_PATH, serverPath); const hostPath = path.join(HOST_SERVER_PATH, serverPath); + const composeFile = path.join(fullPath, "docker-compose.yml"); const { stdout } = await execAsync( - `docker compose ps --format json 2>/dev/null`, - { cwd: hostPath } + `docker compose -f "${composeFile}" --project-directory "${hostPath}" ps --format json 2>/dev/null` ); if (stdout.trim()) { const containers = stdout @@ -1260,11 +1261,14 @@ router.post("/servers/start", async (req, res) => { console.log(`[Admin] 서버 시작 중: ${serverPath}`); - // docker-compose up -d 실행 (호스트 경로 사용) - const { stdout, stderr } = await execAsync("docker compose up -d", { - cwd: hostPath, - timeout: 60000, // 60초 타임아웃 - }); + // docker compose up -d 실행 + // -f: 컨테이너 내부 경로로 파일 지정 + // --project-directory: 호스트 경로로 volumes 해석 + const composeFile = path.join(fullPath, "docker-compose.yml"); + const { stdout, stderr } = await execAsync( + `docker compose -f "${composeFile}" --project-directory "${hostPath}" up -d`, + { timeout: 60000 } + ); console.log(`[Admin] 서버 시작 완료: ${serverPath}`); res.json({ @@ -1302,11 +1306,12 @@ router.post("/servers/stop", async (req, res) => { console.log(`[Admin] 서버 종료 중: ${serverPath}`); - // docker-compose down 실행 (호스트 경로 사용) - const { stdout, stderr } = await execAsync("docker compose down", { - cwd: hostPath, - timeout: 60000, // 60초 타임아웃 - }); + // docker compose down 실행 + const composeFile = path.join(fullPath, "docker-compose.yml"); + const { stdout, stderr } = await execAsync( + `docker compose -f "${composeFile}" --project-directory "${hostPath}" down`, + { timeout: 60000 } + ); console.log(`[Admin] 서버 종료 완료: ${serverPath}`); res.json({