From 67329baf76b050dd684e2cd34c5f70ac268bbfb0 Mon Sep 17 00:00:00 2001 From: Hyein Jeong Date: Thu, 14 Nov 2024 18:14:36 +0900 Subject: [PATCH] =?UTF-8?q?[BE][Chore]=20#166=20:=20docker-compose,=20ngin?= =?UTF-8?q?x=20=EC=84=A4=EC=A0=95=20=EB=B0=8F=20=EB=B0=B1=EC=97=94?= =?UTF-8?q?=EB=93=9C=20dockerfile=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - docker-compose 파일 작성 - nginx 파일 작성 - 백엔드 dockerfile 작성 - local 테스트 완료 --- backend/Dockerfile | 29 +++++++++++++++++++++++++++++ docker-compose.yml | 27 +++++++++++++++++++++++++++ nginx.conf | 27 +++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 backend/Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx.conf diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 00000000..3122d97e --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,29 @@ +# 1. 베이스 이미지 설정 (Node.js 18 버전 사용) +FROM node:18 + +# 2. 작업 디렉토리 설정 +WORKDIR /app + +# 3. root 폴더의 package.json, pnpm-lock.yaml, pnpm-workspace.yaml 파일을 복사 +COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ + +# 4. pnpm을 설치 +RUN npm install -g pnpm + +# 5. 전체 의존성 설치 (root) +RUN pnpm install + +# 6. backend 폴더를 컨테이너로 복사 +COPY backend /app/backend + +# 7. 작업 디렉토리 backend로 이동 +WORKDIR /app/backend + +# 8. backend 의존성 설치 +RUN pnpm install + +# 9. 백엔드 실행 +CMD ["pnpm", "run", "dev"] + +#10. 백엔드 포트 설정 +EXPOSE 3001 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..b6916480 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: '3' +services: + backend: + build: + context: . + dockerfile: backend/Dockerfile + ports: + - "3001:3001" + environment: + - NODE_ENV=production + networks: + - app-network + + nginx: + image: nginx:alpine + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf + ports: + - "80:80" + networks: + - app-network + depends_on: + - backend + +networks: + app-network: + driver: bridge diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 00000000..09cc6772 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,27 @@ +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server { + listen 80; + + location /api/ { + proxy_pass http://backend:3001; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + # TODO: 프론트엔드 요청 처리 (나중에 활성화) + location / { + root /usr/share/nginx/html; + index index.html; + } + } +}