fix: docker compose 실행 시 -f와 --project-directory 옵션 사용

- -f: 컨테이너 내부 경로로 compose 파일 지정
- --project-directory: 호스트 경로로 volumes 해석
- cwd 대신 명시적 경로 지정으로 ENOENT 에러 해결
This commit is contained in:
caadiq 2025-12-29 13:57:09 +09:00
parent 210740f278
commit 2c15101ad8

View file

@ -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({