# PURPOSE: # Build a clean Docker image for KnowFlow AI. # # THIS IMAGE SUPPORTS: # - Phase 2 CLI backend testing # - JupyterLab development # - Future Streamlit app execution # # Docker solves common local issues: # - broken .venv # - wrong Python version # - missing packages # - Ubuntu pip restrictions # - Jupyter kernel conflicts # ============================================================ # ============================================================ # 1. BASE IMAGE # ============================================================ # python:3.11-slim is lightweight but still suitable for this app. # ============================================================ FROM python:3.11-slim # ============================================================ # 2. PYTHON ENVIRONMENT SETTINGS # ============================================================ # PYTHONDONTWRITEBYTECODE=1: # Prevents Python from writing .pyc files. # # PYTHONUNBUFFERED=1: # Makes logs appear immediately in Docker output. # # PIP_NO_CACHE_DIR=1: # Reduces Docker image size by not storing pip cache. # ============================================================ ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV PIP_NO_CACHE_DIR=1 # ============================================================ # 3. SET WORKING DIRECTORY # ============================================================ # All project files live inside /app in the container. # ============================================================ WORKDIR /app ENV PYTHONPATH=/app # ============================================================ # 4. INSTALL SYSTEM DEPENDENCIES # ============================================================ # build-essential: # Needed by some Python packages during installation. # # curl: # Useful for health checks and debugging. # # git: # Useful if packages need git-based installation. # ============================================================ RUN apt-get update && apt-get install -y \ build-essential \ curl \ git \ && rm -rf /var/lib/apt/lists/* # ============================================================ # 5. COPY REQUIREMENTS FIRST # ============================================================ # Docker layer caching: # If requirements.txt does not change, Docker can reuse this layer. # ============================================================ COPY requirements.txt /app/requirements.txt # ============================================================ # 6. INSTALL PYTHON PACKAGES # ============================================================ RUN python -m pip install --upgrade pip setuptools wheel \ && pip install -r /app/requirements.txt # ============================================================ # 7. REGISTER JUPYTER KERNEL # ============================================================ # This allows JupyterLab inside Docker to use a clean kernel. # ============================================================ RUN python -m ipykernel install \ --sys-prefix \ --name knowflow-ai-docker \ --display-name "Python (KnowFlow AI Docker)" # ============================================================ # 8. COPY PROJECT FILES # ============================================================ # .dockerignore controls what should NOT be copied. # .env must NOT be copied into the image. # ============================================================ COPY . /app # ============================================================ # 9. CREATE RUNTIME FOLDERS # ============================================================ RUN mkdir -p /app/data/raw \ && mkdir -p /app/vector_db \ && mkdir -p /app/outputs \ && mkdir -p /app/logs # ============================================================ # 10. EXPOSE PORTS # ============================================================ # 8888 = JupyterLab # 8501 = Streamlit # ============================================================ EXPOSE 8888 EXPOSE 8501 # ============================================================ # 11. DEFAULT COMMAND # ============================================================ # Starts JupyterLab for development. # # SECURITY NOTE: # Token is disabled here only for local development. # Do NOT expose this container publicly with token disabled. # ============================================================ CMD ["jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--allow-root", "--NotebookApp.token=", "--NotebookApp.password="]