Dockerfile•1.16 kB
# Multi-stage build for efficiency
FROM node:20-alpine AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
COPY tsconfig.json ./
# Install dependencies
RUN npm ci --only=production
# Copy source code
COPY src/ ./src/
# Build the application
RUN npm run build
# Production stage
FROM node:20-alpine AS runtime
WORKDIR /app
# Copy built application and dependencies
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S mcp -u 1001
# Change ownership of the app directory
RUN chown -R mcp:nodejs /app
USER mcp
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD node -e "
const http = require('http');
const options = { hostname: 'localhost', port: 3000, path: '/health', timeout: 2000 };
const req = http.request(options, (res) => process.exit(res.statusCode === 200 ? 0 : 1));
req.on('error', () => process.exit(1));
req.end();
"
# Start the HTTP server
CMD ["node", "dist/http-server.js"]