
Table of Contents
By Khimananda Oli | Last reviewed: August 2026
Running proprietary AI models through public APIs creates data residency risks, unpredictable costs, and latency issues that many teams in Nepal and abroad can no longer ignore. When you self-host LLMs with Ollama and Open WebUI, you regain full control over your inference stack while keeping sensitive data entirely within your own infrastructure. This guide walks you through a production-grade deployment using Docker, covering GPU acceleration, persistent storage, and security hardening based on real-world implementations I have managed throughout 2026.
How do you install Ollama and Open WebUI with Docker Compose?
The most reliable way to self-host LLMs with Ollama and Open WebUI in 2026 is through Docker Compose. This approach ensures reproducible deployments, simplifies updates, and makes it straightforward to apply the security hardening principles covered in my Ubuntu security hardening guide. Before starting, verify that your host has the NVIDIA Container Toolkit installed if you plan to use GPU acceleration, as the runtime will fail silently otherwise.
Create the compose file
Create a file named docker-compose.yml in your project directory. This configuration mounts named volumes for both model weights and application state, preventing data loss during container restarts or upgrades.
version: "3.9"
services:
ollama:
image: ollama/ollama:latest
container_name: ollama
restart: unless-stopped
ports:
- "127.0.0.1:11434:11434"
volumes:
- ollama_models:/root/.ollama
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
environment:
- OLLAMA_KEEP_ALIVE=24h
- OLLAMA_NUM_PARALLEL=4
open-webui:
image: ghcr.io/open-webui/open-webui:main
container_name: open-webui
restart: unless-stopped
ports:
- "3000:8080"
volumes:
- open_webui_data:/app/backend/data
environment:
- OLLAMA_BASE_URL=http://ollama:11434
- WEBUI_AUTH=true
- ENABLE_SIGNUP=false
depends_on:
- ollama
volumes:
ollama_models:
open_webui_data: Start the stack and pull a model
- Run
docker compose up -dto start both services in detached mode. - Verify GPU detection with
docker exec ollama nvidia-smi. - Pull your first model:
docker exec ollama ollama pull llama3.1:8b. - Access the interface at
http://localhost:3000and create an admin account.
A common mistake is binding Ollama’s port to 0.0.0.0. Always bind to 127.0.0.1 unless you have a reverse proxy with authentication in front. Exposing the raw Ollama API to the internet allows anyone to execute arbitrary prompts and consume your compute resources without restriction.
What hardware do you need to self-host LLMs effectively?
Hardware requirements depend entirely on the model size and quantization level you intend to run. When you self-host LLMs with Ollama and Open WebUI, VRAM is the primary bottleneck. System RAM matters only when models spill over from GPU memory, which drastically reduces token generation speed. For teams evaluating whether to rent vs buy GPUs for AI workloads, understanding these thresholds prevents costly over-provisioning.
| Model Size | Quantization | Min VRAM | Recommended GPU | Use Case |
|---|---|---|---|---|
| 7B–8B | Q4_K_M | 6 GB | RTX 4060 / T4 | Chat, summarization, dev assistance |
| 13B–14B | Q4_K_M | 10 GB | RTX 4070 Ti / A10G | RAG, code completion, analysis |
| 30B–34B | Q4_K_M | 20 GB | RTX 4090 / A10 | Complex reasoning, multi-step tasks |
| 70B | Q4_K_M | 40 GB | A100 40GB / 2× RTX 4090 | Production-grade general intelligence |
If you are running on CPU-only hardware, expect 2–5 tokens per second for 8B models. That is usable for batch processing but frustrating for interactive chat. Apple Silicon Macs with unified memory perform surprisingly well due to high bandwidth, though they lack CUDA ecosystem compatibility. For Nepali organizations dealing with import restrictions, a single RTX 4090 workstation often delivers better price-performance than cloud GPU rentals for sustained internal workloads.
How do you configure RAG and persistent storage in Open WebUI?
Retrieval-Augmented Generation transforms a generic model into a domain-specific assistant. Open WebUI includes a built-in vector store powered by ChromaDB or Elasticsearch, eliminating the need for separate infrastructure like external vector databases for most team-scale deployments. Documents uploaded through the UI are chunked, embedded using a local sentence-transformer model, and stored in the mounted volume.
Optimize chunking and embedding
Default settings work for quick tests but produce poor retrieval quality for technical documentation. Adjust these parameters in the Admin Panel → RAG Settings:
- Chunk Size: Set to 512 tokens for code repositories, 1024 for policy documents.
- Chunk Overlap: Use 10–15% of chunk size to preserve context across boundaries.
- Embedding Model: Use
nomic-embed-textorbge-m3instead of the default. Pull via Ollama:ollama pull nomic-embed-text. - Top-K: Start with 5 results. Increase only if recall is insufficient; higher values add noise.
Store embeddings on fast NVMe storage. Vector search latency directly impacts perceived responsiveness. If you are running on a VPS with network-attached storage, consider dedicating a local SSD partition to the open_webui_data volume. Back up this volume regularly using strategies from my server backup guide, as re-indexing large document collections takes hours.
How do you secure a self-hosted LLM stack for production?
Security is where most self-hosted AI deployments fail. Treating your local LLM stack like a toy leads to data leaks and compliance violations. When you self-host LLMs with Ollama and Open WebUI for business use, apply the same rigor you would to any production service handling sensitive information.
Network and access controls
- Reverse Proxy: Place Nginx or Caddy in front of Open WebUI. Terminate TLS there. Never expose port 8080 directly.
- Authentication: Enable
WEBUI_AUTH=trueand disable public signup after creating admin accounts. Integrate with OIDC/LDAP for team environments. - Firewall Rules: Allow inbound traffic only on ports 443 (HTTPS). Block all direct access to 11434 and 8080 from external interfaces.
- Rate Limiting: Configure rate limits at the reverse proxy layer. A single user running infinite loops can saturate GPU memory and deny service to others.
Data governance and compliance
For Nepali fintech or healthcare organizations, data residency is non-negotiable. Self-hosting solves this inherently, but you must still implement audit trails. Open WebUI logs all conversations to its SQLite database. Export these logs periodically and integrate with centralized logging systems like those described in my structured logging best practices article. Encrypt the Docker volumes at rest using LUKS or filesystem-level encryption. Regularly review which models are pulled and remove unused ones to reduce attack surface and disk consumption.
When should you choose self-hosting over cloud LLM APIs?
Self-hosting is not universally superior. It trades operational simplicity for control and privacy. Choose to self-host LLMs with Ollama and Open WebUI when data cannot leave your jurisdiction, when monthly API spend exceeds hardware amortization costs, or when you need offline operation. Cloud APIs remain better for bursty workloads, cutting-edge frontier models, or teams without DevOps capacity. For a deeper analysis of this decision framework, see my guide on building vs buying LLM features.
In practice, many organizations adopt a hybrid approach. Run routine internal tasks on self-hosted 8B–14B models for speed and privacy. Route complex reasoning or customer-facing outputs to cloud APIs with proper PII redaction. Open WebUI supports configuring multiple Ollama endpoints and external API providers simultaneously, making this split transparent to end users.
Getting Started with Your Private AI Stack
Deploying a private inference stack removes vendor dependency and keeps sensitive data under your control. Start with an 8B quantized model on available hardware to validate your workflow before investing in dedicated GPUs. Monitor GPU utilization and token throughput to right-size your infrastructure. If you need help designing a compliant, production-ready AI infrastructure for your team, reach out to discuss your requirements.