Here’s a step-by-step recipe for running Ollama in Docker, pulling models into it, and pointing OpenWebUI at those models. Feel free to tweak paths, ports or model names to suit your setup.
1. Prerequisites
• Docker installed
• (Optional) NVIDIA‐Docker / GPU drivers if you want GPU inference
• A folder on your host to persist Ollama models, e.g. ~/ollama‐models
2. Spin up the Ollama “server” container
bash
# Create the host directory if needed
mkdir -p ~/ollama-models
# Run Ollama server, mounting your models folder
docker run -d \
--name ollama-server \
-p 11434:11434 \
-v ~/ollama-models:/root/.ollama/models \
ollama/ollama:latest server
– 11434 is Ollama’s default gRPC/API port.
– Models you pull will be stored in ~/ollama-models.
Check it’s up:
bash
docker logs ollama-server
# look for “Listening on 0.0.0.0:11434”
3. Pull or install models into Ollama
Now that the server is running, you can pull any Ollama-compatible model:
bash
# Pull Llama 2 7b, for example
docker exec -it ollama-server ollama pull llama2:7b
# Or any other Ollama model
docker exec -it ollama-server ollama pull gpt4all/llama-quantized
You’ll see the model folder appear under ~/ollama-models/llama2_7b (or similar).
4. Run OpenWebUI and point it at your Ollama server
When you start OpenWebUI in Docker, set a few env vars so it can talk to Ollama:
bash
docker run -d \
--name openwebui \
-p 7860:7860 \
-e OLLAMA_API_URL=http://host.docker.internal:11434 \
-e OLLAMA_MODELS_PATH=/root/.ollama/models \
-v ~/ollama-models:/root/.ollama/models \
--gpus all \ # remove if on CPU only
ghcr.io/openwebui/openwebui:latest
Notes:
• host.docker.internal lets the OpenWebUI container reach your host’s Ollama server.
• You mount the same ~/ollama-models so both containers share the filesystem.
• Adjust --gpus all if you want GPU support; omit for CPU inference.
In the model selector dropdown, choose the Ollama backend (often labeled “Ollama”).
You should see a list such as llama2:7b or whatever you pulled.
Select it, hit Run, and you’re chatting with your newly added model!
6. Troubleshooting
• If OpenWebUI can’t reach Ollama:
– From inside the OpenWebUI container, try curl http://host.docker.internal:11434
– Check your Docker network settings.
• Model not listed?
– Ensure it’s fully downloaded in ~/ollama-models
– Restart the OpenWebUI container so it re-scans the folder
• GPU not detected?
– Verify nvidia-smi inside both containers
– Make sure you’re using the --gpus all flag and NVIDIA container toolkit
7. Quick Example (all-in-one script)
bash
# 1) Ollama server
docker run -d --name ollama-server -p 11434:11434 \
-v ~/ollama-models:/root/.ollama/models \
ollama/ollama:latest server
# 2) Pull a model
docker exec -it ollama-server ollama pull llama2:7b
# 3) OpenWebUI
docker run -d --name openwebui -p 7860:7860 \
-e OLLAMA_API_URL=http://host.docker.internal:11434 \
-e OLLAMA_MODELS_PATH=/root/.ollama/models \
-v ~/ollama-models:/root/.ollama/models \
--gpus all \
ghcr.io/openwebui/openwebui:latest
That’s it! You now have Ollama models available inside OpenWebUI. 🎉
Let me know if you hit any snags or need help with specific models.