2025-08-13 18:05:26 +02:00

46 lines
1.1 KiB
Docker

# Build stage
FROM node:18-alpine as builder
WORKDIR /app
# Copy package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm ci --only=production --silent
# Copy the rest of the application
COPY . .
# Build the application for production
RUN npm run build
# Production stage - serve with nginx
FROM nginx:alpine
# Create non-root user
RUN addgroup -g 1001 -S nginx && \
adduser -S nginx -u 1001
# Copy built app from builder stage
COPY --from=builder /app/build /usr/share/nginx/html
# Copy custom nginx configuration
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Create necessary directories and set permissions
RUN mkdir -p /var/cache/nginx /var/log/nginx /var/run \
&& chown -R nginx:nginx /var/cache/nginx /var/log/nginx /var/run /usr/share/nginx/html \
&& chmod -R 755 /usr/share/nginx/html
# Switch to non-root user
USER nginx
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:80/ || exit 1
# Expose port
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]