SpacyModelCreator / Dockerfile
WebashalarForML's picture
Update Dockerfile
f0525d6 verified
raw
history blame
1.77 kB
# Use an official Python runtime as a parent image
FROM python:3.9-slim
# Set environment variables for Python
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set environment variables for Hugging Face and Matplotlib cache
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
ENV HF_HOME=/app/.cache/huggingface
ENV MPLCONFIGDIR=/app/.cache/matplotlib
# Create cache directories and assign permissions
RUN mkdir -p /app/.cache/huggingface /app/.cache/matplotlib
# Install system dependencies
RUN apt-get update && apt-get install -y \
libgl1-mesa-glx \
libgomp1 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user and group
RUN groupadd -r appgroup && useradd -r -g appgroup appuser
# Create necessary directories
RUN mkdir -p /app/flask_sessions /app/uploads /app/data /app/JSON /app/Models /app/logs /tmp/matplotlib /tmp/transformers_cache
# Set permissions for app directories
RUN chown -R appuser:appgroup /app /tmp/matplotlib /tmp/transformers_cache \
&& chmod -R 755 /app /tmp/matplotlib /tmp/transformers_cache
# Set working directory
WORKDIR /app
# Copy the requirements file into the container at /app
COPY requirements.txt /app/
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt
# Copy the rest of the application code to /app
COPY . /app/
# Ensure app user owns the app directory
RUN chown -R appuser:appgroup /app
# Switch to non-root user
USER appuser
# Expose the port that the app runs on
EXPOSE 7860
# Set environment variables for Flask
ENV FLASK_APP=app.py
ENV FLASK_ENV=production
# Command to run the Flask app using Gunicorn with 1 worker
CMD ["gunicorn", "--workers=1", "--bind=0.0.0.0:7860", "--timeout=120", "app:app"]