62 lines
1.4 KiB
Docker
62 lines
1.4 KiB
Docker
# Dockerfile for Nuxt.js Application
|
|
# Multi-stage build for optimized image size
|
|
|
|
# Stage 1: Build Stage
|
|
FROM node:20-alpine AS builder
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
|
|
# Install dependencies
|
|
RUN npm ci
|
|
|
|
# Copy application files
|
|
COPY . .
|
|
|
|
# Build the application
|
|
RUN npm run build
|
|
|
|
# Stage 2: Production Stage
|
|
FROM node:20-alpine AS runner
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
|
|
# Install production dependencies only (skip postinstall script)
|
|
RUN npm ci --omit=dev --ignore-scripts
|
|
|
|
# Copy built application from builder stage
|
|
COPY --from=builder /app/.output /app/.output
|
|
COPY --from=builder /app/.nuxt /app/.nuxt
|
|
COPY --from=builder /app/nuxt.config.ts /app/nuxt.config.ts
|
|
COPY --from=builder /app/node_modules /app/node_modules
|
|
|
|
# Create non-root user for security
|
|
RUN addgroup -g 1001 -S nodejs && \
|
|
adduser -S nuxtjs -u 1001 && \
|
|
chown -R nuxtjs:nodejs /app
|
|
|
|
# Switch to non-root user
|
|
USER nuxtjs
|
|
|
|
# Expose port
|
|
EXPOSE 3000
|
|
|
|
# Set environment variables
|
|
ENV NODE_ENV=production
|
|
ENV HOST=0.0.0.0
|
|
ENV PORT=3000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
|
|
CMD node -e "require('http').get('http://localhost:3000/api/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
|
|
|
|
# Start the application
|
|
CMD ["node", ".output/server/index.mjs"]
|