All Newbie, Semua Tentang Ilmu

Recent

How to Run a Local LLM with Ollama and Open WebUI on Ubuntu

Running a language model locally is no longer exotic. A single curl installs Ollama, one command pulls a model, and a browser UI turns it into something you can actually use. No API keys, no per-token billing, and nothing leaves your machine.

Circuit board of an NVIDIA RTX 4090 graphics card with the AD102 GPU die in the centre
Foto: Fritzchens Fritz, CC0, via Wikimedia Commons

Ringkasan singkat

  • Ollama listens on localhost:11434 by design.
  • --add-host=host.docker.internal links the UI.
  • Model size decides speed more than CPU does.
  • Keep the endpoint off the public internet.

This guide sets up Ollama on Ubuntu, adds Open WebUI in Docker, and covers the hardware limits that decide whether the experience is pleasant or painful.

Prerequisites

  • Ubuntu 22.04/24.04, 8 GB RAM minimum for small models.
  • Docker for the web interface.
  • Optional: NVIDIA GPU with drivers and the container toolkit.

1. Install Ollama

curl -fsSL https://ollama.com/install.sh | sh
systemctl status ollama --no-pager

The installer creates a systemd service listening on 127.0.0.1:11434. Keeping it on localhost is deliberate: an open model endpoint on a public IP is an invitation.

2. Pull a model

ollama pull llama3.2
ollama run llama3.2

Model size determines hardware needs more than anything else:

Model classRAM/VRAMExperience
3B parameters~4 GBFast on CPU, good for drafting
7–8B parameters~8 GBUsable on CPU, comfortable on GPU
13–14B parameters~16 GBNeeds a GPU for interactive speed
70B parameters48 GB+Multi-GPU territory
ollama list
ollama ps

3. GPU acceleration

nvidia-smi
ollama ps

If the model loads into VRAM, the output shows GPU usage. When it spills to system RAM, tokens per second drop sharply. For NVIDIA containers, install the container toolkit and pass --gpus=all later when starting Open WebUI.

Request flow from browser to Open WebUI, Ollama, and the local modelBrowserchat UIOpen WebUI:3000DockerOllama:11434localhostModelGPU / RAM
Diagram: Request flow from browser to Open WebUI, Ollama, and the local model

4. Run Open WebUI

docker run -d -p 3000:8080 \
  --add-host=host.docker.internal:host-gateway \
  -v open-webui:/app/backend/data \
  --name open-webui --restart always \
  ghcr.io/open-webui/open-webui:main

host.docker.internal lets the container reach Ollama on the host. Without it, the UI starts but shows no models.

With a GPU:

docker run -d -p 3000:8080 --gpus=all \
  --add-host=host.docker.internal:host-gateway \
  -v open-webui:/app/backend/data \
  --name open-webui --restart always \
  ghcr.io/open-webui/open-webui:main

5. First login

Open http://SERVER_IP:3000. The first account becomes admin. Models appear in the selector; if the list is empty, check docker logs open-webui for a connection error to port 11434.

6. Keep it private

Neither service should face the internet directly. Reach them through a VPN, or put a reverse proxy with authentication in front. A local model endpoint is not designed to be a public API.

7. Manage disk usage

du -sh ~/.ollama/models
ollama rm MODEL_NAME

Each model is a few gigabytes. Removing unused ones is the simplest way to reclaim space; the chat history in Open WebUI lives in its own volume.

8. Use it from the command line

curl http://127.0.0.1:11434/api/generate \
  -d '{"model":"llama3.2","prompt":"Explain WireGuard in one paragraph","stream":false}'

The API is plain HTTP on localhost and mirrors what the UI does. Set stream:true to receive tokens as they are produced, which is what most chat clients expect.

9. A custom model with a system prompt

FROM llama3.2
SYSTEM """You answer in short, factual paragraphs and always show commands."""
PARAMETER temperature 0.3
ollama create assistant -f Modelfile
ollama run assistant

Baking a system prompt into a model keeps the behaviour consistent across clients, instead of retyping instructions in every conversation.

10. Settings worth changing early

Two defaults surprise new users. First, context length: a large window consumes memory per conversation, so a lower value keeps more requests fast. Second, model visibility — restrict which models each user can see once you add accounts, otherwise a large model pulled for testing becomes everyone's default.

Chats are stored in the open-webui volume. Back that volume up together with your other service data; it is the only place the conversation history exists.

Troubleshooting

SymptomCauseFix
UI loads, no models listedContainer cannot reach the hostAdd --add-host=host.docker.internal:host-gateway
Very slow repliesModel too large for available memoryUse a smaller model or enable GPU
CUDA out of memoryModel plus context exceeds VRAMLower context size, smaller model
Connection refused on 11434Ollama not runningsystemctl status ollama
Remote access failsService bound to localhostUse a VPN rather than binding publicly

FAQ

Do I need a GPU?

No, but it changes the experience. Small models are usable on CPU; anything above 8B becomes slow for conversation.

Is my data sent anywhere?

Inference happens locally. Open WebUI stores chats in its volume; telemetry settings are visible in the admin panel.

Can several people use it?

Yes. Open WebUI supports multiple accounts and per-user chat history. Size the hardware for concurrent requests.

Which model should I start with?

A 3B model to test the setup, then an 8B model if the hardware allows it.





0 comments:

Post a Comment