IKHLAA / Dockerfile
munals's picture
Create Dockerfile
0cba116 verified
# ── Stage 1: Build React frontend ───────────────────────────────────────────
FROM node:18-slim AS frontend-build
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm ci
COPY frontend/ ./
# Point API calls to /api/ which Nginx will proxy to the backend
ENV VITE_API_BASE_URL=/api
RUN npm run build
# ── Stage 2: Python backend + Nginx ─────────────────────────────────────────
FROM python:3.10-slim
# Install Nginx and system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
nginx \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /code
# Install Python dependencies
COPY backend/requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
# Copy backend source
COPY backend/ /code/backend/
# Copy built frontend from Stage 1
COPY --from=frontend-build /app/frontend/dist /code/frontend/dist
# Configure Nginx: proxy /api/ to FastAPI, serve frontend for everything else
RUN echo 'server { \
listen 7860; \
location /api/ { proxy_pass http://127.0.0.1:8000/; } \
location / { root /code/frontend/dist; try_files $uri $uri/ /index.html; } \
}' > /etc/nginx/sites-enabled/default
# Startup script: run Nginx + FastAPI together
RUN printf '#!/bin/bash\nnginx &\ncd /code/backend && uvicorn main:app --host 127.0.0.1 --port 8000\n' \
> /code/start.sh && chmod +x /code/start.sh
EXPOSE 7860
CMD ["/code/start.sh"]