Dockerfile Trình tạo cho Node.js
Tạo các tệp Docker sẵn sàng sản xuất cho các ứng dụng Node.js. Hỗ trợ Express, Next.js, NestJS, v.v. với các phương pháp hay nhất.
# Stage 1: Dependencies FROM node:20-alpine AS deps RUN apk add --no-cache libc6-compat WORKDIR /app COPY package.json package-lock.json ./ RUN npm ci --only=production # Stage 2: Builder FROM node:20-alpine AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . RUN npm run build # Stage 3: Runner FROM node:20-alpine AS runner WORKDIR /app ENV NODE_ENV production RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nodeuser COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/dist ./dist COPY --from=builder /app/package.json ./ USER nodeuser EXPOSE 3000 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD wget -qO- http://localhost:3000/health || exit 1 CMD ["npm", "start"]
node_modules npm-debug.log yarn-debug.log yarn-error.log .pnpm-debug.log .git .gitignore .env .env.local .env.development .env.production .env*.local *.log *.md .DS_Store .idea .vscode coverage .nyc_output dist build .next out .turbo Dockerfile .dockerignore docker-compose*.yml .github tests __tests__ *.test.js *.test.ts *.spec.js *.spec.ts