elearning/Frontend-Learner/Dockerfile

39 lines
1.4 KiB
Text
Raw Permalink Normal View History

# --- Build Stage ---
FROM node:20 AS build-stage
# กำหนดโฟลเดอร์ทำงานใน Container
WORKDIR /app
# คัดลอกไฟล์จัดการ dependencies
COPY package*.json ./
# ติดตั้ง dependencies (ใช้ npm ci เพื่อความแม่นยำของเวอร์ชัน)
RUN npm ci
# คัดลอกไฟล์ทั้งหมดในโปรเจกต์
COPY . .
# สั่ง Build โปรเจกต์ Nuxt 3 (จะได้โฟลเดอร์ .output)
RUN npm run build
# --- Production Stage ---
FROM node:20 AS production-stage
# กำหนดโฟลเดอร์ทำงาน
WORKDIR /app
# คัดลอกเฉพาะโฟลเดอร์ .output ที่ได้จากการ build (ประหยัดพื้นที่ Container)
COPY --from=build-stage /app/.output ./.output
# กำหนดตัวแปรสภาพแวดล้อม (Environment Variables) สำหรับ Production
ENV PORT=3000
ENV NODE_ENV=production
# แจ้ง Port ที่ Container จะใช้งาน
EXPOSE 3000
# คำสั่งสำหรับเริ่มการทำงานของ Nuxt 3 Server
# ใช้ node รันไฟล์ entry point ที่สร้างจากการ build
CMD ["node", ".output/server/index.mjs"]