MedicalAIWiki / Dockerfile
AleksanderObuchowski's picture
Use existing UID 1000 instead of creating new user
86aa5b0
# Multi-stage build for React + Node.js application
FROM node:18-alpine AS base
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Create app directory
WORKDIR /app
# Copy package files
COPY package*.json ./
COPY backend/package*.json ./backend/
COPY frontend/package*.json ./frontend/
# Install dependencies
RUN npm ci --only=production && \
cd backend && npm ci --only=production && \
cd ../frontend && npm ci
# Frontend build stage
FROM base AS frontend-build
WORKDIR /app/frontend
COPY frontend/ .
RUN npm run build
# Production stage
FROM node:18-alpine AS production
# Install dumb-init
RUN apk add --no-cache dumb-init
# Use existing user with UID 1000 (required by HF Spaces)
# No need to create user - HF Spaces already has one
# Set working directory
WORKDIR /app
# Copy backend dependencies and source
COPY --from=base --chown=1000:1000 /app/backend/node_modules ./backend/node_modules
COPY --chown=1000:1000 backend/ ./backend/
COPY --chown=1000:1000 data/ ./data/
# Copy built frontend
COPY --from=frontend-build --chown=1000:1000 /app/frontend/dist ./frontend/dist
# Switch to user with UID 1000
USER 1000
# Expose port
EXPOSE 3001
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3001/api/algorithms', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) }).on('error', () => process.exit(1))"
# Start the application
CMD ["dumb-init", "node", "backend/server.js"]