Files
n8n-mcp/Dockerfile
czlonkowski 3e037898c8 fix: simplify Docker build to resolve multi-platform failures
## Root cause
- Docker buildx memory options were incorrectly formatted
- Database build during Docker image creation was failing on multi-platform builds
- n8n native dependencies caused issues across different architectures

## Solution
- Removed invalid buildx driver-opts configuration
- Eliminated database build stage from Dockerfile
- Now using pre-built nodes.db file (11MB) from repository
- Fixed .dockerignore to include nodes.db in build context
- Added .dockerignore to version control (was incorrectly gitignored)

## Benefits
- Faster builds (no n8n package installation during build)
- More reliable multi-platform builds (amd64 + arm64)
- Simpler Dockerfile (3 stages instead of 4)

Database can still be rebuilt locally using 'npm run rebuild' when needed.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-16 16:05:25 +02:00

88 lines
2.5 KiB
Docker

# Optimized Dockerfile - uses pre-built database for faster, more reliable builds
# Stage 1: Dependencies (includes n8n for building)
FROM node:20-alpine AS deps
WORKDIR /app
COPY package*.json ./
# Configure npm for reliability
RUN npm config set fetch-retries 5 && \
npm config set fetch-retry-mintimeout 20000 && \
npm config set fetch-retry-maxtimeout 120000 && \
npm config set fetch-timeout 300000
# Install all dependencies including n8n packages
RUN npm ci
# Stage 2: Builder (compiles TypeScript)
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build TypeScript
RUN npm run build
# Stage 3: Minimal Runtime (no n8n packages)
FROM node:20-alpine AS runtime
WORKDIR /app
# Install only essential runtime tools
RUN apk add --no-cache curl && \
rm -rf /var/cache/apk/*
# Create package.json with only runtime dependencies
RUN echo '{ \
"name": "n8n-mcp-runtime", \
"version": "1.0.0", \
"private": true, \
"dependencies": { \
"@modelcontextprotocol/sdk": "^1.12.1", \
"better-sqlite3": "^11.10.0", \
"sql.js": "^1.13.0", \
"express": "^5.1.0", \
"dotenv": "^16.5.0" \
} \
}' > package.json
# Install only runtime dependencies
RUN npm config set fetch-retries 5 && \
npm config set fetch-retry-mintimeout 20000 && \
npm install --production --no-audit --no-fund
# Copy built application
COPY --from=builder /app/dist ./dist
# Copy pre-built database from source
COPY data/nodes.db ./data/
# Copy minimal required files
COPY src/database/schema-optimized.sql ./src/database/
COPY .env.example ./
# Add container labels
LABEL org.opencontainers.image.source="https://github.com/czlonkowski/n8n-mcp"
LABEL org.opencontainers.image.description="n8n MCP Server - Optimized Version"
LABEL org.opencontainers.image.licenses="Sustainable-Use-1.0"
LABEL org.opencontainers.image.title="n8n-mcp-optimized"
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001 && \
chown -R nodejs:nodejs /app
# Copy entrypoint script
COPY docker/docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Switch to non-root user
USER nodejs
# Expose HTTP port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://127.0.0.1:3000/health || exit 1
# Optimized entrypoint
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["node", "dist/mcp/index.js"]