Dockerfile.serviceā¢2.16 kB
# AnyCrawl MCP Server with Nginx Dockerfile
# Multi-stage build with nginx integration
# Build stage
FROM node:18-alpine AS builder
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache \
python3 \
make \
g++ \
curl
# Copy package files
COPY package*.json ./
# Install all dependencies (including dev dependencies for build)
RUN npm ci && npm cache clean --force
# Copy source code
COPY . .
# Build the application
RUN npm run build
# Production stage with nginx
FROM node:18-alpine AS production
# Install runtime dependencies and nginx
RUN apk add --no-cache \
curl \
netcat-openbsd \
dumb-init \
nginx
# Create app user
RUN addgroup -g 1001 -S nodejs && \
adduser -S anycrawl -u 1001
# Set working directory
WORKDIR /app
# Copy built application from builder stage
COPY --from=builder --chown=anycrawl:nodejs /app/dist ./dist
COPY --from=builder --chown=anycrawl:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=anycrawl:nodejs /app/package*.json ./
# Copy nginx configuration
COPY --chown=anycrawl:nodejs docker/nginx.conf /etc/nginx/nginx.conf
# Copy entrypoint script
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh && \
chown anycrawl:nodejs /usr/local/bin/entrypoint.sh
# Create nginx directories and set permissions
RUN mkdir -p /var/log/nginx /var/lib/nginx /var/cache/nginx && \
chown -R anycrawl:nodejs /var/log/nginx /var/lib/nginx /var/cache/nginx && \
chmod -R 755 /var/log/nginx /var/lib/nginx /var/cache/nginx
# Switch to non-root user
USER anycrawl
# Expose ports
EXPOSE 80 3000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost/health || exit 1
# Set default environment variables
ENV NODE_ENV=production
ENV ANYCRAWL_MODE=MCP_AND_SSE
ENV ANYCRAWL_MCP_PORT=3000
ENV ANYCRAWL_SSE_PORT=3001
ENV ANYCRAWL_HOST=0.0.0.0
ENV CLOUD_SERVICE=true
ENV ANYCRAWL_BASE_URL=https://api.anycrawl.dev
# Use dumb-init to handle signals properly
ENTRYPOINT ["dumb-init", "--"]
# Start the application
CMD ["/usr/local/bin/entrypoint.sh"]