fix: docker-compose 실행 시 호스트 경로 사용
- 컨테이너 내부 경로와 호스트 경로 분리 - docker compose 명령은 호스트 경로로 실행 - 상대 경로 volumes이 올바르게 작동하도록 수정
This commit is contained in:
parent
0b9445e576
commit
210740f278
1 changed files with 17 additions and 16 deletions
|
|
@ -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초 타임아웃
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue