ai-analyze / Dockerfile
sksameermujahid's picture
Update Dockerfile
e935a89 verified
# Use Python 3.10 slim image for smaller size
FROM python:3.10-slim
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
libgl1-mesa-glx \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
libgomp1 \
libglib2.0-0 \
libfontconfig1 \
libgtk-3-0 \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libv4l-dev \
libxvidcore-dev \
libx264-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libatlas-base-dev \
libhdf5-dev \
libhdf5-serial-dev \
libhdf5-103 \
python3-dev \
python3-pip \
python3-setuptools \
python3-wheel \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create cache directories with proper permissions
RUN mkdir -p /tmp/huggingface /tmp/matplotlib /tmp/ultralytics /tmp/fontconfig \
&& chmod 777 /tmp/huggingface /tmp/matplotlib /tmp/ultralytics /tmp/fontconfig
# Set environment variables for cache directories
ENV TRANSFORMERS_CACHE=/tmp/huggingface
ENV HF_HOME=/tmp/huggingface
ENV MPLCONFIGDIR=/tmp/matplotlib
ENV YOLO_CONFIG_DIR=/tmp/ultralytics
ENV FONTCONFIG_PATH=/tmp/fontconfig
# Copy requirements first for better caching
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy application files
COPY . .
# Create necessary directories
RUN mkdir -p uploads property_images
# Download YOLO model
RUN python -c "from ultralytics import YOLO; YOLO('yolov8n.pt')"
# Set environment variables
ENV PYTHONPATH=/app
ENV FLASK_APP=app.py
ENV FLASK_ENV=production
ENV PORT=7860
# Expose port
EXPOSE 7860
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/health || exit 1
# Run the application
CMD ["python", "app.py"]