Spaces:
Sleeping
Sleeping
# Use the official Ollama Docker image | |
FROM ollama/ollama:latest | |
# Set the working directory inside the container | |
WORKDIR /app | |
# Define the model you want to download (replace with your chosen sub-500MB model) | |
# Examples: smollm:135m, smollm:360m, tinyllama:1.1b-chat-v1.0-q2_K | |
ENV OLLAMA_MODEL_NAME="smollm:135m" | |
# Pull the model during the Docker build process | |
# This ensures the model is present when the container starts, | |
# reducing startup time and avoiding dynamic downloads. | |
# The `ollama pull` command can be slow, so pulling it once here is efficient. | |
RUN ollama pull ${OLLAMA_MODEL_NAME} | |
# Set OLLAMA_HOST to listen on all network interfaces inside the container | |
# This is crucial for Hugging Face Spaces to be able to connect to Ollama. | |
ENV OLLAMA_HOST="0.0.0.0:11434" | |
# Allow all origins for the API (CORS configuration) | |
ENV OLLAMA_ORIGINS="*" | |
# Expose the port Ollama listens on | |
EXPOSE 11434 | |
# Command to start the Ollama server. | |
# The base image typically has ENTRYPOINT ["ollama"], so CMD just provides the argument. | |
CMD ["serve"] | |
# Optional: Add metadata for Hugging Face Spaces (improves discoverability) | |
LABEL org.opencontainers.image.title="Ollama with a tiny model" | |
LABEL org.opencontainers.image.description="Runs Ollama with a pre-loaded model less than 500MB" | |
LABEL org.opencontainers.image.licenses="MIT" | |
LABEL org.opencontainers.image.authors="Your Name/Org" |