# Stage 1: Build the application | |
FROM node:16 AS builder | |
WORKDIR /app | |
COPY package.json package-lock.json ./ | |
RUN npm install | |
COPY . . | |
RUN npm run build | |
# Stage 2: Serve the application with Nginx | |
FROM nginx:alpine | |
# Start as root to perform initial setup tasks | |
# Copy the built app to Nginx's serve directory | |
COPY --from=builder /app/dist /usr/share/nginx/html | |
# Create directories and set permissions | |
RUN mkdir -p /var/cache/nginx /var/run /var/log/nginx /var/tmp/nginx && \ | |
chmod -R 777 /var/cache/nginx /var/run /var/log/nginx /var/tmp/nginx | |
# Provide a custom nginx.conf that sets pid and client_body_temp_path to directories with proper permissions | |
COPY nginx.conf /etc/nginx/nginx.conf | |
# Expose port 8080 | |
EXPOSE 8080 | |
# Start Nginx in the foreground | |
CMD ["nginx", "-g", "daemon off;"] | |