Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
# Dockerfile for a Node.js application FROM node:20-alpine AS base # Set working directory (created if not exists) WORKDIR /app # Install OS deps in one layer, clean cache RUN apk add --no-cache \ dumb-init \ curl # Copy dependency manifests first (cache-friendly) COPY package.json package-lock.json ./ # Install production dependencies only RUN npm ci --omit=dev --ignore-scripts # Copy application source COPY src/ ./src/ COPY config/ ./config/ # Create non-root user RUN addgroup -S appgroup && adduser -S appuser -G appgroup \ && chown -R appuser:appgroup /app USER appuser # Document the port (metadata only) EXPOSE 3000 # Set default environment ENV NODE_ENV=production PORT=3000 # Health check HEALTHCHECK --interval=30s --timeout=5s --retries=3 \ CMD curl -f http://localhost:3000/health || exit 1 # Use dumb-init for proper signal handling ENTRYPOINT ["dumb-init", "--"] CMD ["node", "src/server.js"]
Result
Open