# MCP Database Server # Multi-stage build for optimal image size # # If using Chinese mirrors, you can configure Docker daemon with: # { # "registry-mirrors": ["https://mirror.ccs.tencentyun.com"] # } # Stage 1: Build FROM node:20-alpine AS builder WORKDIR /app # Use Chinese npm mirror (optional, uncomment if needed) # RUN npm config set registry https://registry.npmmirror.com # Install build dependencies RUN apk add --no-cache python3 make g++ # Copy package files COPY package*.json ./ # Install all dependencies (including devDependencies for build) RUN npm ci # Copy source code COPY tsconfig.json ./ COPY src/ ./src/ COPY scripts/ ./scripts/ # Build TypeScript RUN npm run build # Prune devDependencies RUN npm prune --production # Stage 2: Runtime FROM node:20-alpine AS runtime WORKDIR /app # Install runtime dependencies only RUN apk add --no-cache dumb-init wget # Create non-root user RUN addgroup -g 1001 -S mcp && \ adduser -u 1001 -S mcp -G mcp # Copy built artifacts COPY --from=builder /app/dist ./dist COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/package.json ./ # Copy config directory structure COPY config/ ./config/ # Create data directory for logs RUN mkdir -p /app/data && chown -R mcp:mcp /app # Switch to non-root user USER mcp # Environment variables with defaults ENV NODE_ENV=production ENV MCP_LOG_LEVEL=info ENV MCP_LISTEN=0.0.0.0:7700 # Expose WebSocket port EXPOSE 7700 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:7700/health || exit 1 # Use dumb-init as PID 1 for proper signal handling ENTRYPOINT ["dumb-init", "--"] # Start server CMD ["node", "dist/src/server.js"]