docsp / Dockerfile
Mohammed Foud
Add application file
039d568
# Use a smaller base image compatible with Spaces
FROM python:3.10-slim
# Set up environment
ENV PORT=7860
ENV SHM_SIZE="1g"
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /app
# Create a non-root user and switch to it
RUN useradd -m -u 1000 user && \
mkdir -p /app/har_and_cookies /app/generated_media && \
chown -R user:user /app
# Install required system dependencies including SSL libraries
RUN apt-get update && \
apt-get install -y --no-install-recommends \
wget \
ca-certificates \
libssl-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Switch to the non-root user
USER user
# Install Python dependencies with --user flag
ENV PATH="/home/user/.local/bin:${PATH}"
RUN pip install --no-cache-dir --user \
uvicorn \
fastapi \
hypercorn \
g4f[all] \
pyopenssl \
cryptography
# Ensure proper Python path configuration
ENV PYTHONPATH="${PYTHONPATH}:/home/user/.local/lib/python3.10/site-packages"
# Ensure the media directories exist with proper permissions
RUN mkdir -p /app/har_and_cookies /app/generated_media && \
chmod 755 /app/har_and_cookies /app/generated_media
# Expose the required port
EXPOSE 7860
# Correct command to run the application with limited providers and debug mode
CMD ["sh", "-c", "python -m g4f.cli api --bind 0.0.0.0:$PORT --debug "]