MogensR's picture
Update Dockerfile
8168272
raw
history blame
1.47 kB
# Use CUDA-enabled base image to match HF Spaces CUDA 12.3
FROM nvidia/cuda:12.3.2-cudnn9-devel-ubuntu22.04
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
GRADIO_SERVER_NAME="0.0.0.0" \
GRADIO_SERVER_PORT="7860" \
DISPLAY=:99
# Set working directory
WORKDIR /app
# Create a non-root user for security
RUN useradd -m myuser && \
chown myuser:myuser /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
ffmpeg \
xvfb \
libglib2.0-0 \
libgomp1 \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Copy requirements first to leverage Docker cache
COPY requirements.txt .
# Install Python dependencies as non-root user
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY --chown=myuser:myuser . .
# Create necessary directories with proper permissions
RUN mkdir -p /tmp/gradio /tmp/model_cache && \
chmod 777 /tmp/gradio /tmp/model_cache && \
chown myuser:myuser /tmp/gradio /tmp/model_cache
# Set proper permissions for the app directory
RUN chmod -R 755 /app
# Expose port
EXPOSE 7860
# Health check to ensure the app is running
HEALTHCHECK --interval=30s --timeout=3s \
CMD curl -f http://localhost:7860/ || exit 1
# Switch to non-root user for security
USER myuser
# Run the application via start.sh to ensure xvfb
CMD ["bash", "start.sh"]