Deploy Ollama + Open WebUI on Docker Compose Stack — Self-hosted AI stack
Complete setup guide for running Ollama + Open WebUI locally on Docker Compose Stack for self-hosted AI stack
Deploy Ollama + Open WebUI on Docker Compose Stack — Self-hosted AI stack
Complete setup guide for running Ollama + Open WebUI locally on Docker Compose Stack for self-hosted AI stack
Deploy Ollama + Open WebUI on Docker Compose Stack Overview Run Ollama + Open WebUI directly on Docker Compose Stack for self-hosted AI stack. Local inference offers privacy, zero latency, and no ongoing API costs. **Specs**: Container · 16GB Ins
Deploy Ollama + Open WebUI on Docker Compose Stack
Overview
Run Ollama + Open WebUI directly on Docker Compose Stack for self-hosted AI stack. Local inference offers privacy, zero latency, and no ongoing API costs.
Specs: Container · 16GB
Installation
bash
Install Ollama — easiest local inference runtime
curl -fsSL https://ollama.com/install.sh | shVerify installation
ollama --version
Download Model
bash
Pull Ollama + Open WebUI (downloads GGUF quantized weights automatically)
ollama pull ollama-+-open-webuiRun interactive chat
ollama run ollama-+-open-webuiStart API server
ollama serve
API available at http://localhost:11434
Python Integration
python
import httpx
from typing import Iteratorclass LocalAI:
"""Interface to local Ollama + Open WebUI running on Docker Compose Stack."""
BASE_URL = "http://localhost:11434"
MODEL = "ollama-+-open-webui"
def chat(self, message: str, system: str = "") -> str:
"""Single-turn chat."""
resp = httpx.post(
f"{self.BASE_URL}/api/chat",
json={
"model": self.MODEL,
"messages": [
{"role": "system", "content": system},
{"role": "user", "content": message}
],
"stream": False
},
timeout=120
)
resp.raise_for_status()
return resp.json()["message"]["content"]
def stream(self, message: str) -> Iterator[str]:
"""Streaming chat for real-time output."""
with httpx.stream(
"POST",
f"{self.BASE_URL}/api/chat",
json={"model": self.MODEL, "messages": [{"role": "user", "content": message}], "stream": True},
timeout=120
) as r:
for line in r.iter_lines():
if line:
import json
chunk = json.loads(line)
if not chunk.get("done"):
yield chunk["message"]["content"]
Usage
ai = LocalAI()
response = ai.chat("Help me with self-hosted AI stack")
print(response)Streaming
for token in ai.stream("Explain self-hosted AI stack step by step"):
print(token, end="", flush=True)
Custom Modelfile
bash
Create optimized configuration for self-hosted AI stack
cat > Modelfile << 'MODELEOF'
FROM ollama-+-open-webuiPARAMETER num_ctx 4096
PARAMETER temperature 0.7
PARAMETER top_p 0.9
SYSTEM "You are an AI assistant specialized in self-hosted AI stack. You run locally on Docker Compose Stack. Be concise, accurate, and helpful."
MODELEOF
ollama create self-hosted-AI-stack-assistant -f Modelfile
ollama run self-hosted-AI-stack-assistant
Performance Profile
Production Setup with FastAPI
python
from fastapi import FastAPI
from pydantic import BaseModelapp = FastAPI(title="Docker Compose Stack AI API")
ai = LocalAI()
class ChatRequest(BaseModel):
message: str
system: str = ""
class ChatResponse(BaseModel):
response: str
model: str
device: str
@app.post("/chat", response_model=ChatResponse)
async def chat_endpoint(req: ChatRequest):
response = ai.chat(req.message, req.system)
return ChatResponse(response=response, model="Ollama + Open WebUI", device="Docker Compose Stack")
@app.get("/health")
async def health():
return {"status": "ok", "model": "Ollama + Open WebUI", "device": "Docker Compose Stack"}
Troubleshooting
Slow inference: Switch to Q4_K_M quantization, reduce context window
Out of memory: Use smaller model or Q3_K_S quant
GPU not used: Install CUDA/Metal drivers, check ollama logs
High latency: Warm up model by sending a dummy request on startup
Resources
相关工具
相关教程
Complete setup guide for running TinyLlama 1.1B locally on Raspberry Pi 5 for home automation assistant
Complete setup guide for running Llama 3.1 8B locally on Apple MacBook M3 for offline productivity AI
Complete setup guide for running Any GGUF Model locally on Ollama Local Server for local development AI