ironGym/webapp/Dockerfile

53 lines
1.2 KiB
Docker

# Stage 1: Build the application
FROM node:18-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Install dependencies
COPY webapp/package.json webapp/package-lock.json ./
RUN npm ci
# Copy the rest of the application
COPY webapp/ .
# Set environment variables for build
ARG DB_URI
ENV DB_URI=${DB_URI:-"mongodb://dummy:password@localhost:27017/dummy"}
ENV NODE_ENV=production
# Build the application
RUN npm run build
# Stage 2: Create the runner image
FROM node:18-alpine AS runner
WORKDIR /app
# Install dependencies only needed for production
RUN apk add --no-cache dumb-init
# Create a non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy the built application from the builder stage
COPY --from=deps /app/public ./public
# Automatically leverage output traces to reduce image size
COPY --from=deps --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=deps --chown=nextjs:nodejs /app/.next/static ./.next/static
# Set the user to non-root
USER nextjs
# Expose the port the app runs on
EXPOSE 3000
# Set the environment variable for the port
ENV PORT 3000
# Use dumb-init to handle signals properly
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
# Start the application
CMD ["node", "server.js"]