# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies including dev dependencies for building
RUN npm ci
# Copy source code
COPY . .
# Build the TypeScript code
RUN npm run build
# Production stage
FROM node:20-alpine
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install only production dependencies
RUN npm ci --only=production && \
npm cache clean --force
# Copy built application from builder stage
COPY --from=builder --chown=nodejs:nodejs /app/dist ./dist
# Switch to non-root user
USER nodejs
# Expose port for HTTP mode
EXPOSE 3000
# Use dumb-init to handle signals properly
ENTRYPOINT ["dumb-init", "--"]
# Default to stdio mode, can be overridden with HN_MCP_HTTP=true
CMD ["node", "dist/index.js"]
# Labels for metadata
LABEL org.opencontainers.image.source="https://github.com/karanb192/hn-mcp"
LABEL org.opencontainers.image.description="Hacker News MCP server for Claude Desktop & AI assistants"
LABEL org.opencontainers.image.licenses="MIT"