🐳 Docker 환경별 설정 분리 및 실행 스크립트 추가

- docker-compose.dev.yml: 개발환경 전용 설정
- docker-compose.prod.yml: 프로덕션환경 전용 설정
- scripts/dev.sh, scripts/prod.sh: 환경별 실행 스크립트
- Dockerfile 및 nginx.conf 추가로 완전한 컨테이너화 구현
- 환경변수를 통한 유연한 API URL 설정
This commit is contained in:
Hyungi Ahn
2025-08-01 13:46:22 +09:00
parent a7e4c0158e
commit 7dbb742981
7 changed files with 198 additions and 0 deletions

36
frontend/Dockerfile Normal file
View File

@@ -0,0 +1,36 @@
# Node.js 18 베이스 이미지 사용
FROM node:18-alpine
# 작업 디렉토리 설정
WORKDIR /app
# 빌드 인자 받기
ARG VITE_API_URL=http://localhost:8000
ENV VITE_API_URL=$VITE_API_URL
# package.json과 package-lock.json 복사
COPY package*.json ./
# 의존성 설치 (플랫폼별 바이너리 다운로드)
RUN npm ci --force
# 소스 코드 복사 (node_modules 제외)
COPY . .
# Vite 빌드
RUN npm run build
# Nginx 이미지로 멀티스테이지 빌드
FROM nginx:alpine
# 빌드된 파일을 nginx로 복사
COPY --from=0 /app/dist /usr/share/nginx/html
# nginx 설정 파일 복사 (필요시)
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 포트 3000 노출
EXPOSE 3000
# nginx 실행
CMD ["nginx", "-g", "daemon off;"]

26
frontend/nginx.conf Normal file
View File

@@ -0,0 +1,26 @@
server {
listen 3000;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
# SPA를 위한 설정 (React Router 등)
location / {
try_files $uri $uri/ /index.html;
}
# API 프록시 설정
location /api/ {
proxy_pass http://tk-mp-backend:8000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 정적 파일 캐싱
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}