From 210740f278d733e3304c8347295a0b05bf2d99c8 Mon Sep 17 00:00:00 2001 From: caadiq Date: Mon, 29 Dec 2025 13:53:12 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20docker-compose=20=EC=8B=A4=ED=96=89=20?= =?UTF-8?q?=EC=8B=9C=20=ED=98=B8=EC=8A=A4=ED=8A=B8=20=EA=B2=BD=EB=A1=9C=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 컨테이너 내부 경로와 호스트 경로 분리 - docker compose 명령은 호스트 경로로 실행 - 상대 경로 volumes이 올바르게 작동하도록 수정 --- backend/routes/admin.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/backend/routes/admin.js b/backend/routes/admin.js index fd5c6bc..841120e 100644 --- a/backend/routes/admin.js +++ b/backend/routes/admin.js @@ -1115,7 +1115,8 @@ import fs from "fs"; import path from "path"; const execAsync = promisify(exec); -const SERVER_BASE_PATH = "/minecraft/server"; +const SERVER_BASE_PATH = "/minecraft/server"; // 컨테이너 내부 경로 (파일 확인용) +const HOST_SERVER_PATH = "/docker/minecraft/server"; // 호스트 경로 (docker-compose 실행용) // 서버 목록 조회 헬퍼 async function getServerList() { @@ -1177,10 +1178,10 @@ 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 { stdout } = await execAsync( - `docker-compose ps --format json 2>/dev/null`, - { cwd: fullPath } + `docker compose ps --format json 2>/dev/null`, + { cwd: hostPath } ); if (stdout.trim()) { const containers = stdout @@ -1241,15 +1242,14 @@ router.post("/servers/start", async (req, res) => { // 이미 실행 중인 서버가 있는지 확인 const runningContainer = await getRunningServer(); if (runningContainer) { - return res - .status(400) - .json({ - error: "이미 실행 중인 서버가 있습니다", - running: runningContainer, - }); + return res.status(400).json({ + error: "이미 실행 중인 서버가 있습니다", + running: runningContainer, + }); } const fullPath = path.join(SERVER_BASE_PATH, serverPath); + const hostPath = path.join(HOST_SERVER_PATH, serverPath); // 호스트 경로 // docker-compose.yml 존재 확인 if (!fs.existsSync(path.join(fullPath, "docker-compose.yml"))) { @@ -1260,9 +1260,9 @@ 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: fullPath, + // docker-compose up -d 실행 (호스트 경로 사용) + const { stdout, stderr } = await execAsync("docker compose up -d", { + cwd: hostPath, timeout: 60000, // 60초 타임아웃 }); @@ -1291,6 +1291,7 @@ router.post("/servers/stop", async (req, res) => { try { const fullPath = path.join(SERVER_BASE_PATH, serverPath); + const hostPath = path.join(HOST_SERVER_PATH, serverPath); // 호스트 경로 // docker-compose.yml 존재 확인 if (!fs.existsSync(path.join(fullPath, "docker-compose.yml"))) { @@ -1301,9 +1302,9 @@ router.post("/servers/stop", async (req, res) => { console.log(`[Admin] 서버 종료 중: ${serverPath}`); - // docker-compose down 실행 - const { stdout, stderr } = await execAsync("docker-compose down", { - cwd: fullPath, + // docker-compose down 실행 (호스트 경로 사용) + const { stdout, stderr } = await execAsync("docker compose down", { + cwd: hostPath, timeout: 60000, // 60초 타임아웃 });