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";
|
import path from "path";
|
||||||
|
|
||||||
const execAsync = promisify(exec);
|
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() {
|
async function getServerList() {
|
||||||
|
|
@ -1177,10 +1178,10 @@ async function getRunningServer() {
|
||||||
// 컨테이너 상태 확인
|
// 컨테이너 상태 확인
|
||||||
async function getContainerStatus(serverPath) {
|
async function getContainerStatus(serverPath) {
|
||||||
try {
|
try {
|
||||||
const fullPath = path.join(SERVER_BASE_PATH, serverPath);
|
const hostPath = path.join(HOST_SERVER_PATH, serverPath);
|
||||||
const { stdout } = await execAsync(
|
const { stdout } = await execAsync(
|
||||||
`docker-compose ps --format json 2>/dev/null`,
|
`docker compose ps --format json 2>/dev/null`,
|
||||||
{ cwd: fullPath }
|
{ cwd: hostPath }
|
||||||
);
|
);
|
||||||
if (stdout.trim()) {
|
if (stdout.trim()) {
|
||||||
const containers = stdout
|
const containers = stdout
|
||||||
|
|
@ -1241,15 +1242,14 @@ router.post("/servers/start", async (req, res) => {
|
||||||
// 이미 실행 중인 서버가 있는지 확인
|
// 이미 실행 중인 서버가 있는지 확인
|
||||||
const runningContainer = await getRunningServer();
|
const runningContainer = await getRunningServer();
|
||||||
if (runningContainer) {
|
if (runningContainer) {
|
||||||
return res
|
return res.status(400).json({
|
||||||
.status(400)
|
|
||||||
.json({
|
|
||||||
error: "이미 실행 중인 서버가 있습니다",
|
error: "이미 실행 중인 서버가 있습니다",
|
||||||
running: runningContainer,
|
running: runningContainer,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const fullPath = path.join(SERVER_BASE_PATH, serverPath);
|
const fullPath = path.join(SERVER_BASE_PATH, serverPath);
|
||||||
|
const hostPath = path.join(HOST_SERVER_PATH, serverPath); // 호스트 경로
|
||||||
|
|
||||||
// docker-compose.yml 존재 확인
|
// docker-compose.yml 존재 확인
|
||||||
if (!fs.existsSync(path.join(fullPath, "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}`);
|
console.log(`[Admin] 서버 시작 중: ${serverPath}`);
|
||||||
|
|
||||||
// docker-compose up -d 실행
|
// docker-compose up -d 실행 (호스트 경로 사용)
|
||||||
const { stdout, stderr } = await execAsync("docker-compose up -d", {
|
const { stdout, stderr } = await execAsync("docker compose up -d", {
|
||||||
cwd: fullPath,
|
cwd: hostPath,
|
||||||
timeout: 60000, // 60초 타임아웃
|
timeout: 60000, // 60초 타임아웃
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1291,6 +1291,7 @@ router.post("/servers/stop", async (req, res) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const fullPath = path.join(SERVER_BASE_PATH, serverPath);
|
const fullPath = path.join(SERVER_BASE_PATH, serverPath);
|
||||||
|
const hostPath = path.join(HOST_SERVER_PATH, serverPath); // 호스트 경로
|
||||||
|
|
||||||
// docker-compose.yml 존재 확인
|
// docker-compose.yml 존재 확인
|
||||||
if (!fs.existsSync(path.join(fullPath, "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}`);
|
console.log(`[Admin] 서버 종료 중: ${serverPath}`);
|
||||||
|
|
||||||
// docker-compose down 실행
|
// docker-compose down 실행 (호스트 경로 사용)
|
||||||
const { stdout, stderr } = await execAsync("docker-compose down", {
|
const { stdout, stderr } = await execAsync("docker compose down", {
|
||||||
cwd: fullPath,
|
cwd: hostPath,
|
||||||
timeout: 60000, // 60초 타임아웃
|
timeout: 60000, // 60초 타임아웃
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue