GPT-OSS / Dockerfile
NeelTA's picture
restart ollama service.
2f8d5bb
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
# you will also find guides on how best to write your Dockerfile
FROM python:3.9
# Install Ollama with retry logic
RUN apt-get update && apt-get install -y wget curl && \
wget -qO- https://ollama.com/install.sh | sh || \
(echo "First install failed, retrying..." && \
sleep 5 && \
wget -qO- https://ollama.com/install.sh | sh)
# Start Ollama with retries
RUN (ollama serve & \
OLLAMA_PID=$! && \
sleep 10 && \
ollama pull gpt-oss:20b && \
kill $OLLAMA_PID) || \
(echo "First pull failed, retrying..." && \
sleep 10 && \
ollama serve & \
OLLAMA_PID=$! && \
sleep 15 && \
ollama pull gpt-oss:20b && \
kill $OLLAMA_PID)
# Create user
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"
WORKDIR /app
# Install Python dependencies
COPY --chown=user ./requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt
# Copy application code
COPY --chown=user . /app
# More reliable CMD with startup delay
CMD ["sh", "-c", "ollama serve & sleep 5 && uvicorn app:app --host 0.0.0.0 --port 7860"]