# Use NVIDIA CUDA base image with Python and Ubuntu FROM nvidia/cuda:12.6.0-devel-ubuntu22.04 # Set environment variables ENV DEBIAN_FRONTEND=noninteractive ENV PYTHONUNBUFFERED=1 ENV TRANSFORMERS_CACHE=/app/cache # Install Python, pip, and other dependencies RUN apt-get update && apt-get install -y \ python3 \ python3-pip \ git \ git-lfs \ curl \ && git lfs install \ && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ && . "$HOME/.cargo/env" \ && rm -rf /var/lib/apt/lists/* # Ensure the `python` command points to `python3` RUN ln -s /usr/bin/python3 /usr/bin/python # Install Python packages from requirements.txt COPY requirements.txt /tmp/ RUN . "$HOME/.cargo/env" && pip install --no-cache-dir -r /tmp/requirements.txt # Add the /app directory as a safe Git directory RUN git config --global --add safe.directory /app # Create a non-root user for better security RUN useradd -m appuser # Set up a writable working directory WORKDIR /app # Create the cache directory RUN mkdir -p /app/cache # Copy project files into the container COPY --chown=appuser:appuser . /app # Ensure the /app directory and its subdirectories are writable by appuser RUN chown -R appuser:appuser /app # Switch to the non-root user for running the application USER appuser # Define the command to run the app CMD ["python", "train.py"]