MogensR's picture
Update Dockerfile
b8aa279
raw
history blame
2.5 kB
# ============================================================================
# MatAnyOne + SAM2 + Gradio Dockerfile (Python 3.10 + CUDA 12.1)
# ============================================================================
# Use NVIDIA CUDA 12.1 base image with Python 3.10
FROM nvidia/cuda:12.1.0-cudnn8-runtime-ubuntu20.04
# Environment settings
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
DEBIAN_FRONTEND=noninteractive
# Install Python 3.10 and system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
python3.10 python3.10-dev python3-pip python3.10-venv \
git wget curl build-essential cmake pkg-config \
ffmpeg libsm6 libxext6 libfontconfig1 libxrender1 \
libgl1-mesa-glx libglib2.0-0 \
libavformat-dev libavcodec-dev libavdevice-dev \
libavutil-dev libswscale-dev libswresample-dev libavfilter-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Create working directory
WORKDIR /app
# Create non-root user
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser
# Upgrade pip and install wheel
RUN python3.10 -m pip install --no-cache-dir --user pip setuptools wheel
# Copy requirements for layer caching
COPY --chown=appuser:appuser requirements.txt .
# Install PyTorch (CUDA 12.1 build)
RUN python3.10 -m pip install --no-cache-dir --user \
torch==2.1.0 \
torchvision==0.16.0 \
torchaudio==2.1.0 \
--extra-index-url https://download.pytorch.org/whl/cu121
# Install core CV/scientific dependencies
RUN python3.10 -m pip install --no-cache-dir --user \
numpy==1.26.4 \
opencv-python-headless==4.10.0.84 \
Pillow>=10.0.1,<11.0 \
scipy==1.13.1 \
av==12.1.0
# Install everything else from requirements.txt
RUN python3.10 -m pip install --no-cache-dir --user -r requirements.txt
# Add user bin to PATH
ENV PATH="/home/appuser/.local/bin:$PATH"
# Copy application code
COPY --chown=appuser:appuser . .
# Create runtime directories
RUN mkdir -p /tmp/model_cache /tmp/processing /tmp/jobs && \
chmod 755 /tmp/model_cache /tmp/processing /tmp/jobs
# Runtime environment variables
ENV GRADIO_SERVER_NAME="0.0.0.0" \
GRADIO_SERVER_PORT="7860" \
MODEL_CACHE_DIR="/tmp/model_cache" \
TORCH_HOME="/tmp/model_cache"
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/ || exit 1
# Expose Gradio port
EXPOSE 7860
# Run application
CMD ["python3.10", "app.py"]