Self-Hosting Local LLMs on Linux: Ollama + Open WebUI
A practical, privacy-first guide to running open-weights AI models on your hardware using Docker Compose.

Cloud-hosted AI models are convenient, but sending sensitive prompts, personal documents, and internal code snippets to third-party servers raises obvious privacy concerns. If you run Linux, you can host open-weights models locally with minimal setup.
This guide walks through setting up Ollama and Open WebUI using Docker Compose on Linux. You will get a clean web interface connected directly to a local inference engine, keeping every byte of data on your local machine.
Hardware requirements and model selection
Before writing configuration files, pick models that fit your hardware. Running local models depends heavily on VRAM or unified memory.
Here is a practical breakdown for popular open-weights models:
8GB VRAM (or RAM): Models in the 7B to 8B parameter range quantized to 4-bit (Q4_K_M). Good choices include
llama3.1:8b,qwen2.5:7b, andmistral:7b.16GB VRAM: 14B models or 8B models running at higher precision (Q8_0).
qwen2.5:14boffers strong reasoning performance in this bracket.24GB VRAM or higher: 32B models such as
qwen2.5:32bor quantized 70B models (llama3.1:70b-instruct-q2_K).
If you do not have a dedicated Nvidia GPU, Ollama runs on the CPU using AVX instructions, though inference speeds will be slower.
Step 1: Install Docker and the Nvidia Container Toolkit
Make sure Docker and Docker Compose are installed on your system.
If you have an Nvidia GPU, install the Nvidia Container Toolkit so Docker containers can access your GPU hardware:
# Add the Nvidia Container Toolkit repository
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb [^ ]* #&[signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] #' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
# Install the toolkit
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
# Configure the Docker daemon and restart
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker
Step 2: Create the Docker Compose configuration
Create a dedicated directory for your local AI stack:
mkdir -p ~/local-ai
cd ~/local-ai
Create a docker-compose.yml file in this directory:
version: '3.8'
services:
ollama:
image: ollama/ollama:latest
container_name: ollama
restart: unless-stopped
volumes:
- ollama_data:/root/.ollama
ports:
- "11434:11434"
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
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
depends_on:
- ollama
volumes:
ollama_data:
open_webui_data:
Note: If you are running purely on CPU without an Nvidia GPU, remove the deploy block under the ollama service.
Step 3: Launch the services and pull models
Start the containers in detached mode:
docker compose up -d
Verify that both containers are running:
docker compose ps
Pull your first model into Ollama by running ollama pull inside the container:
# Pull Llama 3.1 8B
docker exec -it ollama ollama run llama3.1:8b
# Pull Qwen 2.5 7B
docker exec -it ollama ollama pull qwen2.5:7b
# Pull Mistral 7B
docker exec -it ollama ollama pull mistral:7b
Step 4: Access and set up Open WebUI
Open your web browser and navigate to http://localhost:3000 (or your server's IP address on port 3000).
Create an admin account: On your first visit, Open WebUI prompts you to register. The first account created automatically gets admin rights.
Select a model: Click the model selector at the top. The models you pulled (
llama3.1:8b,qwen2.5:7b, etc.) will appear automatically because Open WebUI communicates with Ollama via internal container networking.Start chatting: Enter your prompt. The interface supports markdown formatting, syntax highlighting, chat histories, and system prompts.
Optimization tips for local inference
Keep models in VRAM: Prevent Ollama from unloading models between queries by setting
OLLAMA_KEEP_ALIVE=24hin your environment settings.Customize system prompts: Define reusable system instructions in Open WebUI to enforce code-only responses or concise answers.
Local document RAG: Use Open WebUI's built-in document feature to upload PDFs or text files and query them privately without external services.
Setting up Ollama with Open WebUI gives you total control over your AI environment. No API keys, no subscription costs, and no third-party data tracking.
Join the discussion
Have a thought or a correction? Send it over — your message opens in your email app.