Self-Host Ollama + Open WebUI with NVIDIA GPU on Ubuntu (Docker Compose Guide)

Overview

This guide shows you how to self-host Ollama and Open WebUI on Ubuntu using Docker Compose with NVIDIA GPU acceleration. Ollama makes it easy to run popular local LLMs (like Llama 3, Mistral, Phi, and Qwen), while Open WebUI provides a clean, multi-user chat interface, prompt management, and model switching. By the end, you will have a persistent, GPU-enabled AI stack reachable in your browser, suitable for personal use or a small team.

Prerequisites

- Ubuntu 22.04 or 24.04 (server or desktop), 16 GB RAM recommended.

- An NVIDIA GPU with recent drivers (8 GB VRAM or more recommended for 7B/8B models).

- Docker Engine and the Docker Compose plugin.

- A user with sudo privileges and outbound internet access.

Step 1 — Install Docker and Docker Compose

If Docker is not installed, run:

sudo apt update && sudo apt install -y ca-certificates curl gnupg

sudo install -m 0755 -d /etc/apt/keyrings

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Verify Docker works: docker version and docker compose version.

Step 2 — Enable NVIDIA GPU in Containers

Install the NVIDIA Container Toolkit so Docker can access your GPU. First, ensure the NVIDIA driver is installed and nvidia-smi works on the host. Then run:

curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg

curl -fsSL https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \

sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

sudo apt update && sudo apt install -y nvidia-container-toolkit

sudo nvidia-ctk runtime configure --runtime=docker

sudo systemctl restart docker

Test inside a container: docker run --rm --gpus all nvidia/cuda:12.4.1-base-ubuntu22.04 nvidia-smi. You should see your GPU listed.

Step 3 — Create the Docker Compose file

Make a new folder for the stack and create compose.yml in it:

mkdir -p ~/ai-stack && cd ~/ai-stack

Use this minimal Compose configuration (Ollama + Open WebUI, GPU-enabled, with persistent volumes):

services:
ollama:
image: ollama/ollama:latest
container_name: ollama
ports:
- "11434:11434"
volumes:
- ollama:/root/.ollama
environment:
- OLLAMA_KEEP_ALIVE=24h
gpus: all
restart: unless-stopped

open-webui:
image: ghcr.io/open-webui/open-webui:latest
container_name: open-webui
depends_on:
- ollama
ports:
- "3000:8080"
environment:
- OLLAMA_BASE_URL=http://ollama:11434
- WEBUI_AUTH=True
volumes:
- openwebui:/app/backend/data
restart: unless-stopped

volumes:
ollama:
openwebui:

This setup exposes Ollama on port 11434 (API) and Open WebUI on 3000 (web). Data persists in Docker volumes, so updates do not erase models or chats.

Step 4 — Launch the stack and pull a model

Start both services in the background:

docker compose up -d

Check logs to confirm GPU access and healthy startup:

docker logs -f ollama and docker logs -f open-webui

Pull your first model (example: Llama 3.1 8B) and verify inference:

docker exec -it ollama ollama pull llama3.1:8b

docker exec -it ollama ollama run llama3.1:8b

Open a browser to http://<your_server_ip>:3000, create your admin account, choose the pulled model, and start chatting.

Step 5 — Secure access and basic hardening

Open WebUI has built-in auth. The Compose file sets WEBUI_AUTH=True, which prompts for signup on first visit. After creating the admin user, disable new registrations by adding ENABLE_SIGNUP=False under the open-webui environment and redeploy with docker compose up -d.

If you will expose the UI on the internet, place it behind a reverse proxy with HTTPS. For example, with Caddy on the same host, you can proxy to port 3000 and get automatic TLS:

my-ai.example.com {
reverse_proxy 127.0.0.1:3000
}

Alternatively, use Nginx and a free TLS certificate from Let's Encrypt. Restrict access with IP allowlists or SSO if available.

Step 6 — Useful environment options

- OLLAMA_KEEP_ALIVE: Keeps models warm for faster first-token latency (e.g., 24h).

- WEBUI_AUTH and ENABLE_SIGNUP: Enable auth and control who can create accounts.

- OLLAMA_NUM_PARALLEL: Limit concurrent requests to protect VRAM.

- OPENAI_API_BASE_URL (Open WebUI): Point tools or plugins to Ollama if needed for compatibility layers.

Step 7 — Backup and update strategy

Your chats and models live in Docker volumes (ollama and openwebui). To back them up quickly, stop the stack and archive the volumes:

docker compose down

docker run --rm -v ollama:/data -v $(pwd):/backup busybox tar czf /backup/ollama-vol.tar.gz -C /data .

docker run --rm -v openwebui:/data -v $(pwd):/backup busybox tar czf /backup/openwebui-vol.tar.gz -C /data .

To update, pull the latest images and redeploy:

docker compose pull && docker compose up -d

Troubleshooting

- No GPU visible in containers: confirm nvidia-smi works on the host, that the NVIDIA Container Toolkit is installed, and that gpus: all is present under the Ollama service.

- Port in use: change 11434 or 3000 in compose.yml if conflicts arise.

- Out of memory (VRAM): try a smaller model variant (e.g., 7B/8B quantized like Q4_K_M), or reduce parallel requests. Example pull: ollama pull llama3.1:8b-instruct-q4_K_M.

- Slow first response: increase OLLAMA_KEEP_ALIVE or keep frequently used models loaded.

What you built

You now have a modern, GPU-accelerated local AI stack with Ollama and Open WebUI running on Docker Compose. It is easy to manage, fast to update, and simple to secure behind HTTPS. Add more models, enable extensions, or integrate with automation tools to turn this into a private, production-ready assistant for your workstation or team.

3.

Run a Local LLM with GPU Acceleration: Deploy Ollama + Open WebUI on Ubuntu via Docker

Overview

This tutorial shows how to deploy a local Large Language Model (LLM) stack on Ubuntu using Docker, with hardware acceleration for NVIDIA or AMD GPUs. We will combine Ollama (model runtime and manager) with Open WebUI (a fast, modern web interface) so you can chat with models like Llama 3.1 or Mistral on your own machine. The steps apply to Ubuntu 22.04/24.04, and are suitable for homelabs and small teams.

Prerequisites

- Ubuntu server or desktop with internet access

- A recent CPU; for GPU acceleration: an NVIDIA GPU with recent drivers, or an AMD GPU with ROCm support

- Sudo privileges and ports 11434 (Ollama) and 3000 (Open WebUI) available

Install Docker Engine

If Docker is not installed, use the official repository to get the latest stable version and the Compose plugin.

sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER
newgrp docker
docker --version
docker compose version

Enable GPU Acceleration (NVIDIA)

Install the NVIDIA Container Toolkit so containers can access the GPU. Ensure the proprietary GPU driver is installed (e.g., 535+). Then run:

curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
curl -fsSL https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt update
sudo apt install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker
nvidia-smi

If nvidia-smi works on the host, the GPU will be available inside the containers when requested.

Enable GPU Acceleration (AMD ROCm)

AMD support relies on ROCm. On supported GPUs and kernels, install ROCm drivers (refer to AMD documentation for your GPU). Start with:

sudo apt update
# Example meta-package (adjust to your distro and GPU generation)
sudo apt install -y rocm-hip-runtime5.7
/opt/rocm/bin/rocminfo

For Docker, we will pass the ROCm devices into Ollama’s container. Note that model availability and performance vary by GPU generation.

Create the Docker Compose file

We will run two services: ollama and open-webui. Create a project directory and a Compose file:

mkdir -p ~/ollama-openwebui
cd ~/ollama-openwebui
nano docker-compose.yml

Paste the following Compose configuration. Choose ONE of the GPU sections (NVIDIA or AMD). If you don’t have a GPU, omit the device configurations to run on CPU.

services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "11434:11434"
    volumes:
      - ollama:/root/.ollama
    # NVIDIA GPU (uncomment for NVIDIA)
    # deploy:
    #   resources:
    #     reservations:
    #       devices:
    #         - driver: nvidia
    #           count: all
    #           capabilities: [gpu]
    # AMD ROCm (uncomment for AMD)
    # devices:
    #   - "/dev/kfd:/dev/kfd"
    #   - "/dev/dri:/dev/dri"
    # environment:
    #   - HSA_OVERRIDE_GFX_VERSION=11.0.0

  open-webui:
    image: ghcr.io/open-webui/open-webui:latest
    container_name: open-webui
    restart: unless-stopped
    depends_on:
      - ollama
    ports:
      - "3000:8080"
    environment:
      - OLLAMA_BASE_URL=http://ollama:11434
    volumes:
      - openwebui:/app/backend/data

volumes:
  ollama:
  openwebui:

Start the stack

Bring the services up in the background, then confirm they’re healthy.

docker compose up -d
docker compose ps

Open your browser and visit http://SERVER_IP:3000. The first login creates an admin account. Open WebUI will auto-connect to Ollama.

Download a model in Ollama

You can pull a model via the Open WebUI interface or the CLI. For example, to pull Llama 3.1 and test it:

docker exec -it ollama ollama pull llama3.1
docker exec -it ollama ollama run llama3.1

In Open WebUI, select the model from the top bar and start chatting. If GPU is configured correctly, inference will run on the GPU.

Securing access

By default, Open WebUI is exposed on port 3000 without TLS. For internet access, put it behind a reverse proxy like Nginx or Caddy with HTTPS, or use a VPN (e.g., Tailscale/WireGuard). On Ubuntu, restrict the firewall to your network:

sudo ufw allow from 192.168.0.0/24 to any port 3000 proto tcp
sudo ufw allow from 192.168.0.0/24 to any port 11434 proto tcp

Updating and backups

To update, pull the latest images and recreate containers without losing data (volumes keep models and UI data):

docker compose pull
docker compose up -d

For backups, snapshot the Docker volumes or copy them to external storage. On a single host, you can export and re-import volumes with standard tar workflows.

Troubleshooting

- GPU not detected in container (NVIDIA): ensure the NVIDIA driver matches the toolkit; run docker run --rm --gpus all nvidia/cuda:12.4.1-base-ubuntu22.04 nvidia-smi. If it fails, recheck the toolkit setup and restart Docker.

- GPU not detected (AMD): verify rocminfo and clinfo on the host. Make sure /dev/kfd and /dev/dri are mapped and the user has permissions. Some older GPUs are unsupported by modern ROCm.

- Slow inference: use a smaller model (e.g., 7B), increase context/kv-caching wisely, and confirm the container is using the GPU. Consider enabling hugepages and ensuring adequate VRAM.

- Port conflicts: change the mapped ports in docker-compose.yml or stop services occupying them.

Cleanup

To stop the stack, run docker compose down. To remove images and volumes too (irreversible), run docker compose down --volumes --rmi all.

You now have a private, GPU-accelerated LLM environment running Ollama with Open WebUI on Ubuntu. This setup is flexible, easy to upgrade, and ideal for secure, local AI experimentation and productivity.

3.

Self-Host Private AI Chat: Deploy Ollama + Open WebUI on Docker (GPU Ready)

If you want a private, fast, and customizable AI chat without sending data to third-party clouds, hosting Ollama with Open WebUI on Docker is a great choice. Ollama runs lightweight local large language models (LLMs) and Open WebUI provides a clean chat interface, prompt management, and model switching. This guide shows you how to deploy both with Docker on Linux or Windows (WSL2), including optional GPU acceleration for NVIDIA or AMD.

Prerequisites

- A 64-bit machine with at least 16 GB RAM for smooth inference (8 GB can work for smaller models).
- Docker Engine and Docker Compose v2 installed.
- For GPU acceleration (optional):
• NVIDIA: Install the latest NVIDIA driver and NVIDIA Container Toolkit.
• AMD: Recent ROCm-supported GPU and drivers. On Linux, make sure /dev/kfd and /dev/dri are present.

Step 1: Prepare folders

Create a working folder to store persistent data. This keeps your models and chat history safe across updates.

mkdir -p ~/ai-stack && cd ~/ai-stack

Step 2: Create a Docker Compose file

The following docker-compose.yml launches two services: ollama (the model runtime) and open-webui (the web interface). It maps volumes for persistence, exposes ports, and connects the web UI to Ollama. GPU support can be enabled with a single line if you use NVIDIA.

version: "3.9"
services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    ports:
      - "11434:11434"
    volumes:
      - ollama:/root/.ollama
    environment:
      - OLLAMA_KEEP_ALIVE=24h
    restart: unless-stopped
    # Enable this line if you have an NVIDIA GPU and the container toolkit installed:
    # gpus: all

  open-webui:
    image: ghcr.io/open-webui/open-webui:latest
    container_name: open-webui
    depends_on:
      - ollama
    environment:
      - OLLAMA_API_BASE=http://ollama:11434
      # Optional: disable public sign-ups after you create the first admin
      # - SIGNUP_ENABLED=false
    ports:
      - "3000:8080"
    volumes:
      - open-webui:/app/backend/data
    restart: unless-stopped

volumes:
  ollama:
  open-webui:

Notes for AMD/ROCm on Linux: Depending on your distribution and drivers, you may need to pass GPU devices to the Ollama container. Add the following under services.ollama if models aren’t using your GPU:

    devices:
      - /dev/kfd:/dev/kfd
      - /dev/dri:/dev/dri
    group_add:
      - "video"
    environment:
      - HSA_OVERRIDE_GFX_VERSION=11.0.0

If you cannot use GPU yet, you can run entirely on CPU by leaving GPU lines out. Start small models first and scale up as resources allow.

Step 3: Start the stack

Run the following to download images and start containers in the background:

docker compose up -d

Verify both containers are healthy:

docker compose ps

Step 4: Access the web interface and pull a model

Open your browser to http://localhost:3000 (or the server’s IP on port 3000). On the first load, Open WebUI will ask you to create an admin account. After that, connect to Ollama automatically via the configured OLLAMA_API_BASE.

You need to download at least one model. You can pull models either from the WebUI’s Models section or via CLI. For example, from the host:

docker exec -it ollama ollama pull llama3.1:8b

Once downloaded, open a new chat in Open WebUI and select the model (e.g., llama3.1:8b). You can then chat, create system prompts, and save conversations.

Step 5: Confirm GPU acceleration (optional)

To check whether the GPU is used, open logs during a generation:

docker logs -f ollama

You should see messages indicating GPU layers offloaded if acceleration is active. On NVIDIA, you can also run nvidia-smi on the host while generating text to confirm utilization.

Step 6: Secure and harden

- Accounts: After creating your admin user, consider disabling public sign-ups by uncommenting SIGNUP_ENABLED=false in the compose file and restarting.
- Network: Run behind a reverse proxy such as Caddy, Nginx, or Traefik to add HTTPS. If you expose it to the internet, restrict access with firewall rules and strong authentication.
- Data: Store volumes on disks with sufficient space. Models can be several gigabytes each.

Step 7: Update, backup, and migrate

- Update images:

docker compose pull
docker compose up -d

- Backup volumes (on the host):

docker run --rm -v ollama:/data -v $PWD:/backup alpine tar czf /backup/ollama-backup.tgz -C / data
docker run --rm -v open-webui:/data -v $PWD:/backup alpine tar czf /backup/open-webui-backup.tgz -C / data

- Migrate to another server by restoring these archives into volumes with the reverse tar process.

Troubleshooting

- Port conflicts: If ports 3000 or 11434 are in use, change the left side of the port mappings in the compose file (e.g., "8081:8080").
- GPU not detected (NVIDIA): Ensure the host driver matches your GPU, the NVIDIA Container Toolkit is installed, and the compose service has gpus: all. Restart Docker after toolkit installs.
- GPU not detected (AMD): Confirm ROCm support for your GPU and kernel, expose /dev/kfd and /dev/dri, and add your user to the video group on the host.
- Out of memory: Choose a smaller model (e.g., 3B/7B variants), reduce context length in the WebUI, or add swap space. On WSL2, limit memory usage or increase it in .wslconfig.

Why this stack?

Ollama provides a simple, consistent way to run many open models locally, with one command per model and automatic quantized formats for laptops and servers. Open WebUI adds a polished interface with multi-model selection, prompt templates, knowledge features, and API compatibility for tools. Together, they give you a private, portable AI chat solution that you control end to end.

With this setup, you can iterate quickly, test new models, and keep your data on your hardware. When you need more speed, enable GPU acceleration or move the same stack to a more powerful server with minimal changes.

Deploy Ollama and Open WebUI with NVIDIA GPU on Ubuntu using Docker (OpenAI-Compatible Local LLM)

Overview

This step-by-step guide shows how to deploy Ollama and Open WebUI on Ubuntu with NVIDIA GPU acceleration using Docker. You will run large language models locally, manage them in a user-friendly web interface, and expose an OpenAI-compatible API for your apps. The tutorial is designed for Ubuntu 22.04 or 24.04 and focuses on a secure, reproducible, and easily maintainable setup.

What You Will Build

You will run two containers: Ollama (the local LLM runtime and API) and Open WebUI (a modern web UI for chat, prompts, and model management). The stack runs on Docker with NVIDIA GPU acceleration via the NVIDIA Container Toolkit, giving you faster inference and the ability to run larger models locally.

Prerequisites

- Ubuntu 22.04 or 24.04 with sudo access
- An NVIDIA GPU with recent drivers (Turing or newer recommended)
- At least 16 GB RAM for medium models; more for large models
- Internet access to pull Docker images and models

Step 1 — Install NVIDIA Drivers and Container Toolkit

If you have not installed NVIDIA drivers, use Ubuntu’s recommended driver installer:

sudo apt update && sudo apt install -y ubuntu-drivers-common
sudo ubuntu-drivers autoinstall
sudo reboot

After reboot, verify the GPU:

nvidia-smi

Install the NVIDIA Container Toolkit so Docker can access the GPU:

curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
curl -fsSL https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list |
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list > /dev/null
sudo apt update && sudo apt install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Step 2 — Install Docker Engine and Compose Plugin

If Docker is not installed, install it from the official repository:

sudo apt update && sudo apt install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Verify:

docker --version && docker compose version

Step 3 — Start Ollama with GPU Acceleration

Create a dedicated Docker network and volume, then run Ollama:

docker network create ai || true
docker volume create ollama
docker run -d --name ollama --restart unless-stopped --gpus all \
-p 11434:11434 -v ollama:/root/.ollama \
-e OLLAMA_ORIGINS="http://localhost:3000,http://127.0.0.1:3000" \
--network ai ollama/ollama:latest

Confirm it is running:

docker logs -f ollama

Step 4 — Launch Open WebUI

Run the web UI and point it at the Ollama container:

docker run -d --name open-webui --restart unless-stopped \
-p 3000:8080 --network ai \
-e OLLAMA_API_BASE_URL=http://ollama:11434 \
open-webui/open-webui:latest

Open your browser to http://localhost:3000 (or the server’s IP:3000). Create an admin account and adjust settings as needed.

Step 5 — Pull a Model and Test

Use the Ollama CLI inside the container to download a model, for example Llama 3.1 8B:

docker exec -it ollama ollama pull llama3.1:8b

Generate text via the API to verify everything works:

curl http://localhost:11434/api/generate -d '{"model":"llama3.1:8b","prompt":"Write a haiku about GPUs."}'

In Open WebUI, choose the model from the dropdown and start chatting. You can download multiple models and switch between them.

Step 6 — Use the OpenAI-Compatible API

Ollama exposes an OpenAI-style API. Point your clients to the local endpoint and use any placeholder key:

export OPENAI_API_BASE=http://localhost:11434/v1
export OPENAI_API_KEY=not-needed

Python example with the OpenAI SDK (chat completions):

pip install openai
python - <<'PY'
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="local")
resp = client.chat.completions.create(model="llama3.1:8b", messages=[{"role":"user","content":"Explain vector databases in one paragraph."}])
print(resp.choices[0].message.content)
PY

Troubleshooting

- If nvidia-smi fails inside containers, re-run sudo nvidia-ctk runtime configure --runtime=docker and restart Docker.
- If the UI cannot see models, confirm OLLAMA_API_BASE_URL is correct and both containers are on the same network.
- For model download failures, check disk space and retry: docker exec -it ollama ollama pull MODEL_NAME.
- If ports are in use, change the host ports (for example, -p 11435:11434 and -p 3001:8080).

Security and Best Practices

- Do not expose port 11434 to the internet without a reverse proxy and auth; bind to localhost or your private network only.
- In Open WebUI, enable authentication and restrict sign-ups in the admin settings.
- Keep images updated: docker pull ollama/ollama:latest && docker pull open-webui/open-webui:latest, then recreate containers.
- Backup volumes regularly: docker run --rm -v ollama:/data -v $(pwd):/backup busybox tar czf /backup/ollama-backup.tgz -C / data.

Optional: docker compose

Prefer a single-file deployment? Create compose.yaml:

services:
ollama:
image: ollama/ollama:latest
restart: unless-stopped
ports: ["11434:11434"]
volumes: ["ollama:/root/.ollama"]
deploy: {}
environment:
- OLLAMA_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
runtime: nvidia
open-webui:
image: open-webui/open-webui:latest
restart: unless-stopped
ports: ["3000:8080"]
environment:
- OLLAMA_API_BASE_URL=http://ollama:11434
depends_on: ["ollama"]
volumes:
ollama:

Start with docker compose up -d. This file is easy to version-control and redeploy on another machine.

Wrap-Up

You now have a fast, private, and flexible local AI stack running on Ubuntu with GPU support. Ollama handles model execution and exposes an OpenAI-compatible API; Open WebUI provides a polished interface for daily use. With Docker, upgrades and backups are simple, and you can iterate quickly as new models and features arrive.

Deploy Local AI on Ubuntu: Ollama + Open WebUI with NVIDIA GPU via Docker Compose

Overview

This step-by-step guide shows you how to deploy a fast, private, and GPU-accelerated AI chat on Ubuntu using two popular open-source tools: Ollama (model runner) and Open WebUI (user interface). We will use Docker Compose and the NVIDIA Container Toolkit so your NVIDIA GPU can accelerate large language models (LLMs) locally. By the end, you will have a browser-based chat UI running on top of a local model with persistent storage and easy updates.

Prerequisites

- A 64-bit Ubuntu 22.04 or 24.04 machine with an NVIDIA GPU (6–8 GB VRAM minimum recommended for smaller models, more for larger ones).
- SSH or terminal access with sudo privileges.
- Internet connectivity and at least 20 GB of free disk space.
- Basic familiarity with Docker.

1) Install NVIDIA Driver and Verify GPU

First, install the recommended NVIDIA driver. If you already have a working proprietary NVIDIA driver and the nvidia-smi command runs, you can skip to the next step.

sudo apt update
sudo ubuntu-drivers autoinstall
sudo reboot

After the reboot, confirm the driver:

nvidia-smi

You should see your GPU listed along with driver and CUDA versions. If not, fix the driver before continuing.

2) Install Docker Engine and Compose

Install Docker from the official repository to ensure you get the latest stable version.

sudo apt update
sudo apt install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER
newgrp docker

Validate Docker:

docker run --rm hello-world

3) Enable GPU in Containers (NVIDIA Container Toolkit)

Install the NVIDIA Container Toolkit to allow Docker containers to access your GPU.

distribution=$(. /etc/os-release; echo $ID$VERSION_ID)
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | \
sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
curl -fsSL https://nvidia.github.io/libnvidia-container/${distribution}/libnvidia-container.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt update
sudo apt install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Test GPU access inside a container:

docker run --rm --gpus all nvidia/cuda:12.3.2-base-ubuntu22.04 nvidia-smi

If the output shows your GPU, you are ready to proceed.

4) Create a Docker Compose Stack for Ollama + Open WebUI

Create a project folder and a docker-compose.yml file. This configuration runs Ollama (the model server) and Open WebUI (the frontend), shares data persistently, and enables GPU acceleration for Ollama.

mkdir -p ~/ai-stack && cd ~/ai-stack
nano docker-compose.yml

Paste the following Compose file:

version: "3.8"
services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "11434:11434"
    volumes:
      - ollama:/root/.ollama
    environment:
      - OLLAMA_HOST=0.0.0.0
    gpus: all

  open-webui:
    image: ghcr.io/open-webui/open-webui:main
    container_name: open-webui
    restart: unless-stopped
    depends_on:
      - ollama
    ports:
      - "3000:8080"
    environment:
      - OLLAMA_BASE_URL=http://ollama:11434
    volumes:
      - open-webui:/app/backend/data

volumes:
  ollama:
  open-webui:

Bring the stack online:

docker compose up -d
docker compose logs -f

Wait until both containers show as healthy or running without errors.

5) Pull a Model and Run Your First Prompt

Ollama downloads models on demand. Pull a popular, instruction-tuned model. Smaller or quantized models are best for GPUs with less VRAM.

# Example: Llama 3.1 8B Instruct
docker exec -it ollama ollama pull llama3.1:8b

# Lower VRAM option (quantized):
docker exec -it ollama ollama pull llama3.1:8b-instruct-q4_K_M

Test generation via API to confirm everything is working:

curl http://localhost:11434/api/generate \
  -d '{"model":"llama3.1:8b","prompt":"Say hello from a local GPU-accelerated LLM."}'

Open your browser to http://<server-ip>:3000, create an account when prompted, select the model you pulled, and start chatting.

6) Performance, Updates, and Autostart

- For best performance, use GPUs with higher VRAM and prefer models that match your hardware capacity. Quantized variants (e.g., q4_K_M) drastically reduce VRAM usage at a small quality trade-off.
- The Compose file uses restart: unless-stopped, so your stack will auto-start after reboots.
- To update images safely, run: docker compose pull && docker compose up -d. Your models and settings persist in the named volumes.

7) Troubleshooting

No GPU in container: Re-check nvidia-smi on the host, verify the NVIDIA Container Toolkit installation, and confirm the gpus: all setting in Compose. Retest with the CUDA container command above. Ensure Secure Boot is disabled if your driver fails to load.

Model fails to load: Choose a smaller or quantized build. For example, use llama3.1:8b-instruct-q4_K_M instead of a full precision model when VRAM is tight.

Port conflicts: Change the mapped ports in docker-compose.yml (for example, 3001:8080 for the UI or 11435:11434 for Ollama) and run docker compose up -d again.

Slow downloads: Models can be large (several GB). Ensure good bandwidth and enough disk space in Docker’s data root and volumes.

8) Security and Remote Access

By default, this setup is intended for local access. If you expose ports to the internet, secure them behind a reverse proxy with TLS (e.g., Caddy, Nginx, or Traefik), enable authentication in Open WebUI, and restrict access with a firewall or a VPN like WireGuard or Tailscale. Keep Docker and base images updated to benefit from security patches.

Wrap-up

You now have a modern, GPU-accelerated local AI stack on Ubuntu with a clean web interface, powered by Ollama and Open WebUI. This setup is easy to maintain, performs well on consumer GPUs, and keeps your data on your own hardware. Add or switch models as needed, tune quantization levels for your GPU, and enjoy private, fast AI inference without relying on external cloud services.

Deploy Ollama and Open WebUI on Ubuntu with NVIDIA GPU Using Docker Compose

Overview

This guide shows how to deploy Ollama (for running local LLMs) together with Open WebUI (a clean ChatGPT-like interface) on Ubuntu 22.04/24.04 using Docker Compose and an NVIDIA GPU. You will install Docker, enable GPU acceleration with the NVIDIA Container Toolkit, run both services, pull a model, and fix common errors. If you do not have a GPU, a CPU-only note is included.

Prerequisites

- Ubuntu 22.04 or 24.04 with sudo access.

- An NVIDIA GPU (Turing or newer recommended) with recent drivers (535+ works well) and at least 8 GB VRAM for medium models.

- Internet connectivity and ports 11434 (Ollama) and 3000 (Open WebUI) available.

Step 1: Verify and Install NVIDIA Drivers

Ensure a recent NVIDIA driver is installed and visible to the system. Check with: nvidia-smi. If it shows driver and GPU details, continue. If not, install a recommended driver and reboot:

sudo ubuntu-drivers install
sudo reboot

Step 2: Install Docker Engine and Compose Plugin

Set up the official Docker repository and install Docker plus the Compose plugin:

sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release; echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER
newgrp docker

Step 3: Install NVIDIA Container Toolkit for Docker

This toolkit exposes your GPU to containers via Docker. Install and restart Docker:

distribution=$(. /etc/os-release; echo $ID$VERSION_ID)
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit.gpg
curl -fsSL https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Test that containers can see the GPU:

docker run --rm --gpus all nvidia/cuda:12.3.0-base-ubuntu22.04 nvidia-smi

Step 4: Create a Docker Compose File

Create a project directory, then a compose file:

mkdir -p ~/ollama-openwebui && cd ~/ollama-openwebui
nano docker-compose.yml

Paste the following content. This maps GPU to Ollama, persists data, and links the UI to the API.

services:
ollama:
image: ollama/ollama:latest
container_name: ollama
restart: unless-stopped
ports:
- "11434:11434"
volumes:
- ollama:/root/.ollama
environment:
- OLLAMA_KEEP_ALIVE=6h
deploy:
resources:
reservations:
devices:
- capabilities: ["gpu"]
# If your Docker Compose supports it, prefer: gpus: all
# gpus: all

open-webui:
image: ghcr.io/open-webui/open-webui:latest
container_name: open-webui
restart: unless-stopped
ports:
- "3000:8080"
environment:
- OLLAMA_BASE_URL=http://ollama:11434
- ENABLE_SIGNUP=false
volumes:
- openwebui:/app/backend/data
depends_on:
- ollama

volumes:
ollama:
openwebui:

Note: If your Compose version errors on deploy.resources..., upgrade Docker Compose and use gpus: all under the ollama service instead.

Step 5: Start the Stack and Pull a Model

Launch both containers:

docker compose up -d

Pull a model into Ollama (example: Llama 3.1 8B). You can pull from the host or exec into the container:

docker exec -it ollama ollama pull llama3.1:8b

Open your browser at http://<server-ip>:3000. Create an admin account on first run (if sign-up is disabled, enable it temporarily or set credentials via UI). Choose the model you pulled and start chatting.

Optional: CPU-Only Mode

If you do not have a supported GPU, remove the GPU settings and add OLLAMA_NO_GPU=1 to the ollama environment. Performance will be slower, so consider smaller models like llama3.1:8b-instruct or mistral.

Security, Updates, and Backups

- Network access: Do not expose port 11434 to the internet. Only expose 3000 (the UI) behind a reverse proxy like Nginx, Traefik, or Caddy with HTTPS.

- Authentication: Open WebUI supports local accounts. Disable public sign-ups by keeping ENABLE_SIGNUP=false and add users manually via the admin panel.

- Updates: Pull new images and recreate containers: docker compose pull && docker compose up -d.

- Backups: Save volumes with docker run --rm -v ollama:/v -v $PWD:/b busybox tar czf /b/ollama.tgz -C /v . and similarly for openwebui. Restore by reversing the process.

Troubleshooting

Open WebUI cannot connect to Ollama: Ensure OLLAMA_BASE_URL=http://ollama:11434 and that both services run on the same default Compose network. Check logs with docker logs open-webui.

GPU not visible in container: Confirm nvidia-smi works on host. Verify toolkit with docker run --rm --gpus all nvidia/cuda:12.3.0-base-ubuntu22.04 nvidia-smi. If Compose does not support GPUs, update to the latest Docker and use gpus: all or start Ollama once with docker run --gpus all to validate.

“could not load libcuda” or CUDA errors: Upgrade to a newer NVIDIA driver, restart Docker, and ensure nvidia-container-toolkit is correctly configured. Run sudo nvidia-ctk runtime configure --runtime=docker && sudo systemctl restart docker.

Permission denied on Docker: Add your user to the docker group (sudo usermod -aG docker $USER) and re-login.

Memory or OOM kills: Use smaller models, reduce concurrent sessions, or increase swap. You can also set OLLAMA_NUM_GPU=1 or adjust GPU split for multi-GPU hosts.

What’s Next

Explore model variants (LLM, vision, embedding) via Ollama’s registry, enable HTTPS with a reverse proxy, and connect automation via the compatible OpenAI API endpoints exposed by Open WebUI. With this setup, you get a fast, private, self-hosted AI chat experience backed by your own hardware.

How to Self‑Host Ollama + Open WebUI with NVIDIA GPU in Docker on Ubuntu (2025 Guide)

Overview

This step-by-step guide shows how to self-host Ollama with Open WebUI using Docker on Ubuntu, with optional NVIDIA GPU acceleration. You will get a modern local AI stack that can run LLMs such as Llama 3.1 or Mistral privately, with a clean web interface, persistent storage, and an easy update path. The tutorial targets Ubuntu 22.04/24.04 and works on servers, workstations, and homelabs.

Prerequisites

- Ubuntu 22.04/24.04, sudo access, and basic command-line knowledge.
- For GPU acceleration: an NVIDIA GPU with up-to-date drivers (CUDA-compatible). CPU-only mode also works; you can skip the GPU steps.

1) Install Docker and Compose

Run the following commands to install Docker Engine and the Compose plugin (official repository):

sudo apt update && sudo apt install -y ca-certificates curl gnupg lsb-release
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER && newgrp docker

2) Enable NVIDIA GPU in Containers (optional)

If your system has a supported NVIDIA GPU, install the driver from Ubuntu’s repo or NVIDIA’s site (e.g., sudo apt install nvidia-driver-535), reboot, and verify nvidia-smi works. Then install the NVIDIA Container Toolkit so Docker can pass GPUs into containers:

curl -fsSL https://nvidia.github.io/nvidia-container-toolkit/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit.gpg
distribution=$(. /etc/os-release; echo $ID$VERSION_ID) && \

echo "deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit.gpg] https://nvidia.github.io/libnvidia-container/$distribution/$(uname -m) /" | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt update && sudo apt install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Test GPU access in Docker:

docker run --rm --gpus all nvidia/cuda:12.3.1-base-ubuntu22.04 nvidia-smi

3) Create a Docker Compose file

We will run two services: Ollama (the model server) and Open WebUI (the web interface). Create a working folder such as ~/ollama-stack and inside it create docker-compose.yml with the following content:

version: "3.9"

services:
ollama:
image: ollama/ollama:latest
container_name: ollama
ports:
- "127.0.0.1:11434:11434"
volumes:
- ollama:/root/.ollama
environment:
- OLLAMA_NUM_PARALLEL=2
- OLLAMA_MAX_LOADED_MODELS=2
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
restart: unless-stopped

open-webui:
image: ghcr.io/open-webui/open-webui:main
container_name: open-webui
depends_on:
- ollama
ports:
- "127.0.0.1:3000:8080"
environment:
- OLLAMA_BASE_URL=http://ollama:11434
volumes:
- openwebui:/app/backend/data
restart: unless-stopped

volumes:
ollama:
openwebui:

Notes: The loopback bindings (127.0.0.1) keep services off the public network; put a reverse proxy in front if you need remote access. If your Docker Compose version complains about the deploy GPU section, remove it and start Ollama with: docker run --gpus all ... or add --gpus all via docker compose overrides.

4) Start the stack and pull a model

Start the services:

docker compose up -d

Pull a model into Ollama (examples for CPU/GPU-capable LLMs):

docker exec -it ollama ollama pull llama3.1:8b
docker exec -it ollama ollama pull mistral:7b

Open your browser to http://localhost:3000, create the first admin user, and select your Ollama model in Open WebUI. You can now chat, run prompts, and manage models from the interface.

5) Optional: Reverse proxy and HTTPS

For secure remote access, put Nginx or Caddy in front of Open WebUI with HTTPS and basic auth or OAuth. Example: expose Open WebUI only on 127.0.0.1:3000 and publish a domain via the proxy to terminate TLS with Let’s Encrypt. Always restrict access; these services should not be open on the public internet without authentication.

6) Performance tips

- Use GPU if available: it accelerates inference dramatically, especially for 13B+ models.
- Tune concurrency with OLLAMA_NUM_PARALLEL and limit memory pressure using OLLAMA_MAX_LOADED_MODELS.
- Choose model sizes that match your VRAM/RAM. For 8 GB VRAM, 7B/8B models work well; for 12–24 GB, 13B–30B is more comfortable.
- Keep images updated: docker compose pull && docker compose up -d.

7) Backup and restore

Your data lives in Docker volumes. To back up:

docker run --rm -v ollama:/data -v $(pwd):/backup alpine tar czf /backup/ollama-vol.tar.gz -C /data .
docker run --rm -v openwebui:/data -v $(pwd):/backup alpine tar czf /backup/openwebui-vol.tar.gz -C /data .

Restore by creating empty volumes and extracting the archives back into them using the same pattern.

8) Troubleshooting

- No GPU inside container: verify nvidia-smi works on the host, ensure NVIDIA Container Toolkit is installed, and try docker run --gpus all to validate. On WSL2, enable GPU support and CUDA toolkit for WSL.
- High RAM usage: reduce parallel requests and use smaller quantizations (e.g., q4_K_M variants).
- Slow downloads: Ollama model downloads depend on upstream mirrors; retry or prefetch models during off-peak hours.
- Port already in use: change 11434 or 3000 in the compose file.

Conclusion

You now have a modern, private AI stack running locally with Docker: Ollama for efficient model serving and Open WebUI for a friendly interface. This setup is easy to update, secure behind a proxy, and flexible for both CPU-only and GPU-accelerated systems. Add or swap models as your needs grow, and keep your data under your control.

How to Run a Local AI Chat with Ollama and Open WebUI on Ubuntu 24.04 (GPU-Ready)

Overview

This tutorial shows how to deploy a private, fast, and GPU-accelerated local AI chat using Ollama and Open WebUI on Ubuntu 24.04. Ollama manages large language models (LLMs) such as Llama 3, while Open WebUI provides a friendly web interface for chatting, prompt management, and basic workflow tools. We will use Docker to keep the setup clean and reproducible, with steps for both CPU-only and NVIDIA GPU acceleration.

Prerequisites

OS: Ubuntu 24.04 (also works on 22.04). Access: sudo-enabled user. Hardware: 8 GB RAM minimum for small models; NVIDIA GPU (optional) with at least 8 GB VRAM for faster inference. Network: Internet access to pull images and models.

Step 1 — Install Docker and basic tools

Update the system and install Docker using the convenience script. Then add your user to the docker group so you can run containers without sudo.
sudo apt update && sudo apt -y upgrade
sudo apt -y install curl ca-certificates gnupg lsb-release
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER && newgrp docker

Step 2 — (Optional) Enable NVIDIA GPU acceleration

If you have an NVIDIA GPU, install the recommended driver, then the NVIDIA Container Toolkit so Docker can use your GPU.
Install driver:
sudo ubuntu-drivers autoinstall && sudo reboot
After reboot, verify:
nvidia-smi

Install NVIDIA Container Toolkit:
sudo bash -c 'curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit.gpg'
sudo bash -c 'curl -fsSL https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | sed "s#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit.gpg] https://#" > /etc/apt/sources.list.d/nvidia-container-toolkit.list'
sudo apt update && sudo apt -y install nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Step 3 — Create a dedicated Docker network and volumes

Networking and volumes keep services isolated and data persistent.
docker network create ai
docker volume create ollama
docker volume create open-webui

Step 4 — Start Ollama (CPU or GPU)

CPU-only:
docker run -d --name ollama --restart unless-stopped --network ai -p 11434:11434 -v ollama:/root/.ollama ollama/ollama:latest

GPU-enabled (NVIDIA):
docker run -d --name ollama --restart unless-stopped --network ai -p 11434:11434 --gpus all -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=compute,utility -v ollama:/root/.ollama ollama/ollama:latest

Step 5 — Download a model

Pull a model inside the Ollama container. Llama 3 8B works well on modern CPUs and mid-range GPUs; Mistral 7B is another good option.
docker exec -it ollama ollama pull llama3:8b
Alternative models: docker exec -it ollama ollama pull mistral:7b

Step 6 — Launch Open WebUI

Run the Open WebUI container and point it to the Ollama service via the Docker network.
docker run -d --name open-webui --restart unless-stopped --network ai -p 3000:8080 -e OLLAMA_BASE_URL=http://ollama:11434 -e OLLAMA_API_BASE_URL=http://ollama:11434 -v open-webui:/app/backend/data ghcr.io/open-webui/open-webui:latest

Open a browser to http://SERVER_IP:3000. Create your admin account on first login. In Settings, select the downloaded model (for example, llama3:8b) and start chatting.

Security hardening

If you only need local access, bind ports to localhost by replacing -p 3000:8080 and -p 11434:11434 with -p 127.0.0.1:3000:8080 and -p 127.0.0.1:11434:11434. For remote access, put a reverse proxy like Nginx or Caddy in front with HTTPS and authentication. Also consider firewall rules to restrict inbound connections to required IPs.

Model and app updates

Update images and models periodically. Pull latest images and recreate containers:
docker pull ollama/ollama:latest && docker pull ghcr.io/open-webui/open-webui:latest
docker stop open-webui ollama && docker rm open-webui ollama
<re-run the docker run commands from above>
Update models as needed:
docker exec -it ollama ollama pull llama3:8b

Backup and restore

Backup persistent data via volumes. From a safe directory:
docker run --rm -v ollama:/data -v $PWD:/backup alpine tar czf /backup/ollama-models.tgz -C /data .
docker run --rm -v open-webui:/data -v $PWD:/backup alpine tar czf /backup/open-webui-data.tgz -C /data .
Restore by creating volumes and extracting archives back into them using similar commands.

Troubleshooting

GPU not detected in containers: Ensure nvidia-smi works on the host, the NVIDIA Container Toolkit is installed, and you used --gpus all. Restart Docker after configuring the toolkit. Verify with docker run --rm --gpus all nvidia/cuda:12.2.0-base-ubuntu22.04 nvidia-smi.

Port conflicts: If ports 3000 or 11434 are in use, change the host ports (e.g., -p 3001:8080).

Slow performance: Prefer GPU models when available, close background apps, and choose smaller models like llama3:8b or mistral:7b. For CPU, disable power saving and use a recent CPU with AVX2.

Clean removal: Stop and remove everything with:
docker rm -f open-webui ollama
docker volume rm open-webui ollama
docker network rm ai

What you built

You now have a modern, private AI stack running locally: Ollama serving LLMs and Open WebUI delivering a polished chat interface. It is portable via Docker, secure when bound to localhost or proxied with TLS, and easy to update. This setup is ideal for prototyping prompts, experimenting with different models, and keeping sensitive data on your own machine.

Deploy a Self-Hosted AI Chatbot with Ollama and Open WebUI on Docker (CPU/GPU)

If you want a fast, private, and cost-effective AI assistant without sending data to third parties, you can self-host one with Ollama and Open WebUI. Ollama runs large language models locally, while Open WebUI gives you a friendly chat interface with features like chat history, prompt templates, and model management. This guide shows how to deploy both using Docker, with optional GPU acceleration for NVIDIA or AMD.

Why this stack

Ollama simplifies running modern models such as Llama 3.1, Mistral, Phi, and more with a single command. Open WebUI connects to Ollama and adds a browser-based chat app, multiple users, and extras like RAG, files, and tools. Docker keeps everything consistent, easy to update, and portable across servers and clouds.

Prerequisites

- A 64-bit Linux host (Ubuntu 22.04/24.04 recommended), macOS, or Windows with WSL2. For production, a Linux VM or server is ideal.
- Docker Engine 24+ and Docker Compose plugin.
- 16 GB RAM minimum (24–32 GB recommended for 8B models; bigger models need more).
- 25–50 GB free disk space per model.
- Optional GPU:
  • NVIDIA: recent driver + nvidia-container-toolkit.
  • AMD: ROCm-capable GPU and kernel/drivers.

Step 1 — Install Docker and (optional) drivers

On Ubuntu, install Docker quickly:

curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
newgrp docker
docker --version
docker compose version

If you have an NVIDIA GPU, install drivers and container toolkit, then restart Docker:

sudo apt update
sudo apt install -y nvidia-driver-535
sudo apt install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker
nvidia-smi

Step 2 — Create a Docker Compose file

Create a project folder, then a docker-compose.yml that runs Ollama and Open WebUI. This setup persists models and app data in Docker volumes and exposes ports 11434 (Ollama) and 3000 (WebUI).

mkdir -p ~/ai-chat && cd ~/ai-chat
cat > docker-compose.yml << 'YAML'
version: "3.8"

services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "11434:11434"
    volumes:
      - ollama:/root/.ollama
    environment:
      - OLLAMA_KEEP_ALIVE=24h
    # For NVIDIA GPU support, uncomment the next line (requires nvidia-container-toolkit)
    # gpus: all

  open-webui:
    image: ghcr.io/open-webui/open-webui:latest
    container_name: open-webui
    restart: unless-stopped
    depends_on:
      - ollama
    environment:
      - OLLAMA_BASE_URL=http://ollama:11434
      - WEBUI_SECRET_KEY=change_this_long_random_string
      - ENABLE_SIGNUP=true
      - DEFAULT_MODELS=llama3.1:8b-instruct
    ports:
      - "3000:8080"
    volumes:
      - openwebui:/app/backend/data

volumes:
  ollama:
  openwebui:
YAML

Step 3 — Launch the stack

Start both services in the background:

docker compose up -d
docker compose ps

Open a browser and visit http://SERVER_IP:3000. On first visit, create an admin account. In Settings, confirm the Ollama endpoint shows http://ollama:11434 and the default model list includes llama3.1:8b-instruct.

Step 4 — Pull a model

You can pull models in the WebUI, or via CLI inside the Ollama container:

docker exec -it ollama ollama pull llama3.1:8b-instruct

After the download, start chatting in Open WebUI. If the model is large or your server is low on RAM, start with a smaller one like mistral:7b-instruct or phi3:mini.

Optional — Enable NVIDIA GPU acceleration

If nvidia-smi works on the host and you installed nvidia-container-toolkit, uncomment gpus: all for the ollama service in docker-compose.yml and redeploy:

docker compose down
sed -n '1,200p' docker-compose.yml
docker compose up -d
docker logs -f ollama

When a model runs, Ollama should log CUDA usage. You can also watch GPU load with nvidia-smi.

Optional — Enable AMD GPU (ROCm)

For AMD GPUs supported by ROCm, use the ROCm image and pass GPU devices into the container. Replace the ollama service with:

  ollama:
    image: ollama/ollama:rocm
    container_name: ollama
    restart: unless-stopped
    ports:
      - "11434:11434"
    volumes:
      - ollama:/root/.ollama
    devices:
      - /dev/kfd
      - /dev/dri
    group_add:
      - video

Then redeploy with docker compose up -d. If you see ROCm capability errors, verify your kernel/driver versions and that your user belongs to the video group.

Secure and expose your WebUI

For public access, put a reverse proxy in front with HTTPS. Caddy makes this easy:

your-domain.example {
  reverse_proxy 127.0.0.1:3000
}

Point DNS to your server, install Caddy, and it will fetch certificates automatically. In Open WebUI, set strong passwords, disable open signup if you do not need it (ENABLE_SIGNUP=false), and consider enabling rate limits at the proxy.

Backups and updates

Your important data lives in two volumes: ollama (models) and openwebui (app data, history). To back them up:

docker compose stop
docker run --rm -v ollama:/src -v $PWD:/backup alpine tar czf /backup/ollama-vol.tgz -C /src .
docker run --rm -v openwebui:/src -v $PWD:/backup alpine tar czf /backup/openwebui-vol.tgz -C /src .
docker compose start

To update images and get the latest features:

docker compose pull
docker compose up -d

Models remain unless you explicitly remove the ollama volume.

Troubleshooting

- Open WebUI cannot connect to Ollama: ensure OLLAMA_BASE_URL points to http://ollama:11434 and both containers share the same Docker network (default in Compose).
- CUDA driver not found: confirm nvidia-smi works on the host; re-run nvidia-ctk; restart Docker; ensure gpus: all is enabled.
- AMD permissions error: check /dev/kfd and /dev/dri are present; add group_add: video; ensure your kernel/ROCm version supports your GPU.
- Out of memory or slow responses: choose a smaller model, or reduce threads and context in the model settings; increase swap as a temporary measure.
- No space left on device: models are large; prune unused images and models with docker image prune and ollama list / ollama rm.

Uninstall cleanly

Stop and remove containers and volumes (this also deletes downloaded models and chat data):

cd ~/ai-chat
docker compose down -v

You now have a private AI chatbot that runs entirely on your hardware. Expand it with more models, plug in document retrieval, or publish it behind a secure HTTPS domain for your team.

How to Deploy Ollama and Open WebUI with Docker (CPU/NVIDIA/AMD) on Ubuntu 22.04/24.04

Overview

This tutorial shows how to deploy a private, local AI stack with Ollama (model runtime) and Open WebUI (chat interface) using Docker on Ubuntu 22.04/24.04. You will learn how to run it on CPU, enable NVIDIA or AMD/ROCm GPU acceleration, secure the web interface, and keep everything up to date. The result is a fast, reliable, and low-maintenance setup suitable for labs, developers, and small teams.

Prerequisites

You need an Ubuntu 22.04 or 24.04 system with sudo access, 16 GB+ RAM (more is better), 20 GB+ free disk space, and a stable internet connection. For GPU acceleration, use a recent NVIDIA GPU with official drivers or a compatible AMD GPU with ROCm-capable kernel and hardware. Ensure ports 11434 (Ollama) and 3000 (Open WebUI) are free. If you plan to expose the service on the internet, prepare a domain name and DNS A/AAAA record pointing to the server.

Step 1: Install Docker Engine and Compose

sudo apt update && sudo apt install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER
newgrp docker

Step 2: GPU Preparation (optional but recommended)

NVIDIA: Install the proprietary driver and the NVIDIA Container Toolkit so Docker can access your GPU.

sudo apt install -y ubuntu-drivers-common
sudo ubuntu-drivers install
sudo reboot

distribution=$(. /etc/os-release; echo $ID$VERSION_ID)
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit.gpg
curl -fsSL https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt update && sudo apt install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

AMD (ROCm): Ensure your GPU is ROCm-capable and the kfd and dri devices are present. Give your user access to the required groups.

sudo usermod -aG render,video $USER
sudo reboot

Step 3: Create a Docker Compose file

Create a working directory like ~/ai-stack, then create docker-compose.yml. The following example starts Ollama and Open WebUI with volumes for persistence. It includes variants for CPU, NVIDIA, and AMD. Only keep one GPU option at a time.

docker-compose.yml (CPU-only by default):

services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
     - "11434:11434"
    volumes:
     - ollama:/root/.ollama
    environment:
     - OLLAMA_KEEP_ALIVE=24h
     - OLLAMA_NUM_THREADS=8
  # For NVIDIA GPU (uncomment the next 4 lines and comment the AMD lines below):
  #   runtime: nvidia
  #   environment:
  #    - NVIDIA_VISIBLE_DEVICES=all
  #    - NVIDIA_DRIVER_CAPABILITIES=compute,utility
  # For AMD ROCm GPU (use the ROCm image and device mappings):
  #   image: ollama/ollama:rocm
  #   devices:
  #    - /dev/kfd
  #    - /dev/dri
  #   group_add:
  #    - "video"
  #    - "render"
  open-webui:
    image: ghcr.io/open-webui/open-webui:latest
    container_name: open-webui
    depends_on:
     - ollama
    restart: unless-stopped
    environment:
     - OLLAMA_API_BASE=http://ollama:11434
    ports:
     - "3000:8080"
    volumes:
     - openwebui:/app/backend/data
volumes:
  ollama:
  openwebui:

Step 4: Start the stack

docker compose up -d

Check containers and logs to confirm both services are healthy.

docker ps
docker logs -f ollama
docker logs -f open-webui

Step 5: Pull a model and test

Use Ollama to download a model. Popular choices are llama3.1:8b, llama3.1:70b (needs more VRAM), mistral, or qwen2. Start with an 8B or 7B model to validate your setup.

docker exec -it ollama ollama pull llama3.1:8b
curl http://localhost:11434/api/tags

Open a browser to http://<server-ip>:3000. The first user that signs up in Open WebUI becomes the admin. In Settings, point the Ollama endpoint to http://ollama:11434 (it is already set via OLLAMA_API_BASE). Create a new chat and pick your model from the dropdown.

Step 6: Optional security and HTTPS

By default, Open WebUI is accessible on port 3000 and provides its own user system. For internet exposure, put it behind an HTTPS reverse proxy and disable public signups after creating the admin. If you use UFW, allow only necessary ports:

sudo ufw allow 22/tcp
sudo ufw allow 80,443/tcp
sudo ufw enable

A simple approach is to add a Caddy or Nginx reverse proxy in front of Open WebUI for automatic TLS. Map your domain (e.g., ai.example.com) to the server, then proxy requests to open-webui:8080. Limit administrative access using firewall rules, strong passwords, and, if available, SSO/OIDC in Open WebUI.

Step 7: Updating and backing up

To update images to the latest versions and apply them with minimal downtime:

cd ~/ai-stack
docker compose pull
docker compose up -d

Your models and chat data live in Docker volumes. Back them up regularly:

docker run --rm -v ollama:/data -v $(pwd):/backup alpine tar czf /backup/ollama-vol-$(date +%F).tgz -C /data .
docker run --rm -v openwebui:/data -v $(pwd):/backup alpine tar czf /backup/openwebui-vol-$(date +%F).tgz -C /data .

Troubleshooting tips

If GPU is not used on NVIDIA, confirm nvidia-smi works on the host and the container runtime is configured. For AMD, ensure /dev/kfd and /dev/dri exist and the container uses the ollama/ollama:rocm image with the proper device mappings. Model loading failures typically indicate insufficient RAM/VRAM; try a smaller quantization or a smaller model. If the UI cannot see Ollama, verify OLLAMA_API_BASE and that containers can resolve each other by service name.

You are done

You now have a modern, private AI chat stack running on Docker with optional GPU acceleration. Ollama keeps model management simple, and Open WebUI provides a clean, multi-user interface. This setup is easy to maintain, portable across servers, and ready for experimentation with different open-source models and embeddings.

Install Open WebUI and Ollama with GPU: Run Local LLMs on Windows and Linux Using Docker

Overview

Want to run modern large language models (LLMs) like Llama 3 locally, with a clean web interface and optional GPU acceleration? This tutorial shows how to deploy Ollama (model runtime) together with Open WebUI (browser UI) using Docker on Windows or Linux. You will get a stable setup that is easy to update, secure by default, and fast on NVIDIA or AMD GPUs. No cloud required.

Prerequisites

- Windows 10/11 (with WSL2) or any recent Linux distribution.
- Docker Desktop on Windows, or Docker Engine on Linux.
- At least 16 GB RAM recommended; SSD storage preferred.
- Optional GPU acceleration: NVIDIA (CUDA) or AMD (ROCm on Linux). CPU-only also works, just slower.

Step 1 — Install Docker

Windows: Install Docker Desktop, enable WSL2, and turn on “Use the WSL 2 based engine.” In Settings → Resources → WSL Integration, enable your Linux distro. If you have an NVIDIA GPU, install the latest NVIDIA driver; Docker Desktop uses WSL2 GPU automatically.

Linux: Install Docker Engine from your distro’s repository or Docker’s official repo. Add your user to the docker group, then log out and back in. Verify with:
docker version

Step 2 — Prepare GPU Support (Optional)

NVIDIA on Windows: Update the NVIDIA driver. Docker Desktop with WSL2 will expose the GPU automatically to containers that request it.

NVIDIA on Linux: Install the NVIDIA driver and the NVIDIA Container Toolkit. Verify with:
docker run --rm --gpus all nvidia/cuda:12.2.0-base-ubuntu20.04 nvidia-smi

AMD on Linux (ROCm): Install ROCm per your distro and ensure /dev/kfd and /dev/dri are present. AMD GPU acceleration is supported with the rocm-tagged Ollama image.

Step 3 — Create a Docker Compose file

Create a project folder (for example, C:\llm or ~/llm) and in it create a file named docker-compose.yml. Choose the variant that fits your hardware. All versions map Open WebUI to localhost only for security.

CPU-only (works everywhere):
version: "3.9"
services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    volumes:
      - ollama:/root/.ollama
    ports:
      - "11434:11434"
  openwebui:
    image: ghcr.io/open-webui/open-webui:latest
    container_name: openwebui
    environment:
      - OLLAMA_API_BASE=http://ollama:11434
    depends_on:
      - ollama
    ports:
      - "127.0.0.1:3000:8080"
volumes:
  ollama:

NVIDIA GPU (Windows or Linux):
version: "3.9"
services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    gpus: all
    environment:
      - OLLAMA_KEEP_ALIVE=24h
    volumes:
      - ollama:/root/.ollama
    ports:
      - "11434:11434"
  openwebui:
    image: ghcr.io/open-webui/open-webui:latest
    container_name: openwebui
    environment:
      - OLLAMA_API_BASE=http://ollama:11434
    depends_on:
      - ollama
    ports:
      - "127.0.0.1:3000:8080"
volumes:
  ollama:

AMD GPU on Linux (ROCm):
version: "3.9"
services:
  ollama:
    image: ollama/ollama:rocm
    container_name: ollama      - "/dev/kfd:/dev/kfd"
      - "/dev/dri:/dev/dri"
    group_add:
      - "video"
    ipc: host
    security_opt:
      - seccomp=unconfined
    cap_add:
      - SYS_PTRACE
    volumes:
      - ollama:/root/.ollama
    ports:
      - "11434:11434"
  openwebui:
    image: ghcr.io/open-webui/open-webui:latest
    container_name: openwebui
    environment:
      - OLLAMA_API_BASE=http://ollama:11434
    depends_on:
      - ollama
    ports:
      - "127.0.0.1:3000:8080"
volumes:
  ollama:

Step 4 — Start the stack

In the project folder, run:
docker compose up -d
This pulls the images and starts both containers. Open WebUI will be available at http://127.0.0.1:3000 and Ollama’s API at http://localhost:11434.

Step 5 — Download a model

Use the Web UI to add a model, or pull one via CLI. For example, to pull Llama 3.1 8B:
docker exec -it ollama ollama pull llama3.1:8b
Then test it:
docker exec -it ollama ollama run llama3.1:8b "Say hello in one sentence."

Step 6 — First login and basic security

Open http://127.0.0.1:3000 in your browser. Create your account and log in. By default, this guide binds the UI to localhost, so it is not exposed to your network. If you need remote access, publish through a reverse proxy with HTTPS or a zero-trust tunnel, and enable authentication in Open WebUI. Keep your Docker host patched and restrict ports with a firewall.

Updating and Maintenance

- Update to the latest images:
docker compose pull && docker compose up -d
- List installed models:
docker exec -it ollama ollama list
- Remove unused models to free space:
docker exec -it ollama ollama rm model-name

Troubleshooting

- GPU not detected: for NVIDIA, run docker run --rm --gpus all nvidia/cuda:12.2.0-base-ubuntu20.04 nvidia-smi. If that fails, update the driver or NVIDIA Container Toolkit. For AMD, ensure /dev/kfd and /dev/dri are present and you used the rocm image variant.
- Slow performance: confirm you pulled a quantized model (e.g., Q4_K_M) or enable GPU. Increase RAM swap if you run out of memory.
- Ports in use: change the host ports in the compose file (e.g., 127.0.0.1:4000:8080 for the UI).
- Logs: check issues with docker compose logs -f ollama and docker compose logs -f openwebui.

Uninstall (Optional)

To stop and remove containers, run:
docker compose down
To remove models and data, also remove the volume:
docker volume rm llm_ollama (adjust name with docker volume ls)

What you achieved

You now have a local, private, and fast LLM environment with a friendly web UI. Thanks to Docker, the stack is reproducible and easy to update. With GPU acceleration, even 7B–13B models become highly responsive for chat, coding help, and offline experimentation—without sending your data to the cloud.

Deploy OpenWebUI and Ollama with NVIDIA GPU on Ubuntu using Docker Compose

Local AI is now practical: with Ollama you can run large language models (LLMs) on your machine, and OpenWebUI gives you a clean, chat-style interface. In this tutorial, you will deploy both on Ubuntu 22.04/24.04 using Docker Compose, with optional NVIDIA GPU acceleration for much faster inference.

Why OpenWebUI + Ollama?

Ollama manages model downloads and provides an OpenAI-compatible API at /v1. OpenWebUI is a lightweight, self-hosted web frontend that connects to Ollama and adds chat history, prompt templates, and simple administration. Together, they create a private, zero-cost alternative to cloud AI for development, prototyping, and offline use.

Prerequisites

- Ubuntu 22.04 LTS or 24.04 LTS with sudo access.
- Stable internet connection and at least 16 GB of RAM recommended for medium models.
- Optional but recommended: an NVIDIA GPU (Turing or newer) with recent drivers for CUDA acceleration.

Step 1 — Install Docker and Docker Compose

sudo apt update
sudo apt install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER

Log out and back in (or reboot) to apply the new group membership so you can run Docker without sudo.

Step 2 — Enable GPU support (NVIDIA Container Toolkit)

If you do not have an NVIDIA GPU, skip to Step 3. If you do, install the proprietary driver first:

sudo ubuntu-drivers install
sudo reboot

After reboot, verify the driver:

nvidia-smi

Install the NVIDIA Container Toolkit so Docker can access the GPU:

curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
distribution=$(. /etc/os-release; echo $ID$VERSION_ID)
curl -fsSL https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt update
sudo apt install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Test Docker GPU access:

docker run --rm --gpus all nvidia/cuda:12.3.2-base-ubuntu22.04 nvidia-smi

Step 3 — Create the Docker Compose file

Create a project directory and the Compose file:

mkdir -p ~/ai-stack && cd ~/ai-stack
nano compose.yml

Paste the following contents and save:

version: "3.9"
services:
ollama:
image: ollama/ollama:latest
container_name: ollama
restart: unless-stopped
ports:
- "11434:11434"
volumes:
- ollama:/root/.ollama
environment:
- OLLAMA_KEEP_ALIVE=5m
- OLLAMA_MAX_LOADED_MODELS=2
gpus: all # Remove this line if you do not have an NVIDIA GPU

openwebui:
image: ghcr.io/open-webui/open-webui:main
container_name: openwebui
restart: unless-stopped
ports:
- "8080:8080"
environment:
- OLLAMA_BASE_URL=http://ollama:11434
- WEBUI_AUTH=True # Require login
volumes:
- openwebui:/app/backend/data
depends_on:
- ollama

volumes:
ollama:
openwebui:

Step 4 — Launch the stack

docker compose up -d

Open OpenWebUI in your browser: http://<your-server-ip>:8080. On first run, create an admin account when prompted. The backend (Ollama) will be reachable at http://ollama:11434 inside the Docker network and at http://<your-server-ip>:11434 from your LAN.

Step 5 — Download a model and test

Pull a model with the Ollama CLI (inside the container) or use OpenWebUI’s “Models” tab:

docker exec -it ollama ollama pull llama3.1:8b

Try a quick prompt:

docker exec -it ollama ollama run llama3.1:8b "Explain what a vector database is in one paragraph."

Return to OpenWebUI and start chatting with the downloaded model. If you have a GPU configured, latency will drop significantly compared to CPU-only mode.

Optional — Secure and expose the UI

- Keep OpenWebUI private on your LAN and enable authentication (WEBUI_AUTH=True) as shown.
- For public access, place a reverse proxy like Caddy, Nginx Proxy Manager, or Traefik in front, and obtain Let’s Encrypt certificates. Bind OpenWebUI to 127.0.0.1:8080 and publish the proxy instead.

Troubleshooting

- GPU not detected: verify nvidia-smi works on the host. Re-run sudo nvidia-ctk runtime configure --runtime=docker and sudo systemctl restart docker. Ensure the gpus: all line is present for the ollama service and restart with docker compose up -d.
- Slow or out-of-memory errors: try a smaller model (for example, llama3.2:3b), or add --num-ctx 2048 in OpenWebUI’s model settings to reduce memory use.
- Port conflicts: change the host ports in the Compose file (e.g., "8081:8080").
- Persistence: models are stored in the ollama volume; UI data (prompts, chats) in the openwebui volume. Back them up with docker run --rm -v ollama:/data -v $(pwd):/backup alpine tar czf /backup/ollama.tar.gz -C / data.

Maintenance tips

- Update images: docker compose pull && docker compose up -d.
- View logs: docker compose logs -f ollama and docker compose logs -f openwebui.
- Use the OpenAI-compatible API: your apps can point to http://<server-ip>:11434/v1 with the model name you downloaded. Most SDKs accept a custom base URL and a dummy API key.

You now have a modern, private AI stack running locally. Iterate on prompts, fine-tune your workflow, and scale up to larger models as your hardware allows—all while keeping your data on your own machine.

Deploy a Private Ollama + Open WebUI Stack with Docker (GPU or CPU)

Overview

This step-by-step guide shows you how to deploy a private local AI stack using Ollama and Open WebUI with Docker. Ollama runs language models locally (LLMs), and Open WebUI provides a friendly browser interface. The setup supports both NVIDIA GPUs for acceleration and CPU-only machines. You will get persistent storage, a clean Docker Compose file, and optional reverse proxy hardening.

Why this stack?

Running models locally gives you fast, private inference with full control. Ollama supports popular models like Llama 3, Mistral, and Phi 3. Open WebUI offers chat history, model switching, prompt templates, and a polished UX. Docker keeps everything reproducible and easy to update. With GPU enabled, throughput improves dramatically; without a GPU, it still works on modern CPUs.

Prerequisites

You need a 64-bit Linux host (Ubuntu 22.04+ recommended), macOS, or Windows with WSL2. Install Docker Engine and Docker Compose Plugin. If you have an NVIDIA GPU on Linux, install the proprietary driver and NVIDIA Container Toolkit so containers can see the GPU. Confirm Docker is functional with a simple hello-world container before proceeding.

Check your GPU (optional but recommended)

On Linux with NVIDIA, verify the driver and CUDA stack are working. The command below should list your GPU. If it fails, resolve driver issues before continuing.

nvidia-smi

Create a project directory

Create a working folder to store the Docker Compose file and your persistent volumes. The same directory will hold your reverse proxy config if you enable it later. For example, use ~/ollama-stack on Linux or a similar path on other systems.

Write the Docker Compose file

Save the following as docker-compose.yml. It defines two services: the Ollama model server and Open WebUI. Volumes ensure model files and chat history survive container updates.

services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "11434:11434"
    volumes:
      - ollama-data:/root/.ollama
    environment:
      - OLLAMA_KEEP_ALIVE=24h
    # GPU: uncomment this block if you have NVIDIA drivers and Container Toolkit installed
    # deploy:
    #   resources:
    #     reservations:
    #       devices:
    #         - driver: nvidia
    #           count: all
    #           capabilities: ["gpu"]

  open-webui:
    image: ghcr.io/open-webui/open-webui:latest
    container_name: open-webui
    restart: unless-stopped
    ports:
      - "3000:8080"
    environment:
      - OLLAMA_BASE_URL=http://ollama:11434
    depends_on:
      - ollama
    volumes:
      - openwebui-data:/app/backend/data

volumes:
  ollama-data:
  openwebui-data:

Start the services

From the folder that contains docker-compose.yml, bring up the stack in the background. The first run will download images; future starts are much faster.

docker compose up -d
docker compose ps

Pull a model

Ollama does not ship with models. Pull one to get started. Llama 3 8B is a great baseline on consumer GPUs or modern CPUs. You can pull models through Open WebUI, but using the CLI is immediate and reliable.

docker exec -it ollama ollama pull llama3:8b
# Alternative models:
# docker exec -it ollama ollama pull mistral
# docker exec -it ollama ollama pull phi3

Open the interface

Visit http://localhost:3000 in your browser. On first load, Open WebUI initializes its database. Select your model (for example, llama3:8b) and start chatting. If you are accessing from another device on the LAN, replace localhost with the host’s IP address.

Enable GPU acceleration (Linux/NVIDIA)

If you have an NVIDIA GPU, install the NVIDIA Container Toolkit so Docker can pass the GPU into the container. After installation, uncomment the GPU block in the Compose file and redeploy. On CPU-only systems, keep the GPU configuration commented out; Ollama will fall back to CPU.

# On Ubuntu:
# 1) Install drivers via the "Additional Drivers" tool or:
# sudo apt-get update && sudo apt-get install -y nvidia-driver-535

# 2) Install NVIDIA Container Toolkit:
# sudo apt-get install -y nvidia-container-toolkit
# sudo nvidia-ctk runtime configure
# sudo systemctl restart docker

# 3) Recreate the stack:
docker compose down
docker compose up -d
# Validate GPU usage:
docker exec -it ollama nvidia-smi

Secure with a reverse proxy (optional)

If you plan to expose the interface on the internet, add a reverse proxy with TLS and HTTP Basic Auth. The example below uses Caddy for automatic HTTPS on a public domain. Replace example.com with your domain and set a strong username and password.

services:
  caddy:
    image: caddy:latest
    container_name: caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
    depends_on:
      - open-webui

# Caddyfile (place next to docker-compose.yml)
# example.com {
#   basicauth {
#     admin JDJhJDEwJHh5eXouLi4  # use `caddy hash-password --plaintext YOURPASS`
#   }
#   reverse_proxy open-webui:8080
# }

Persist and back up your data

Models and chat history live in Docker volumes named ollama-data and openwebui-data. Back them up by stopping the stack and using docker run --rm -v VOL:/data -v "$PWD":/backup alpine tar to archive each volume. Restoring is the reverse: create an empty volume and extract the tarball into it.

Update the stack

To update to the latest images, pull and recreate. Your data volumes remain intact. If a model gets corrupted or partially downloaded, remove it with ollama rm MODEL and pull again.

docker compose pull
docker compose up -d
docker exec -it ollama ollama list

Troubleshooting

If Open WebUI cannot reach Ollama, ensure the OLLAMA_BASE_URL uses the service name ollama (not localhost) inside Docker. If you see “could not select device driver with capabilities gpu,” the NVIDIA toolkit is missing or misconfigured; confirm nvidia-smi works on the host and restart Docker. If ports are already in use, change 11434 and 3000 in the Compose file to free ports. For slow responses on CPU, try smaller models (for example, llama3:8b-instruct) or quantized variants.

Performance tips

Use GPU when available for large models and higher throughput. Pin the model that matches your VRAM; 8B models typically fit in 8–12 GB of VRAM with quantization. Increase OLLAMA_KEEP_ALIVE to avoid cold starts. If running on SSD-backed storage, model loading is faster. On multi-user setups, place the stack behind a reverse proxy and consider segmenting access per user.

What you built

You now have a private, locally hosted AI chat interface backed by Ollama and Open WebUI, packaged with Docker for easy management. It runs fully offline, can leverage your GPU, and is simple to back up and update. From here, explore custom prompt templates, load additional models, or integrate the HTTP API for programmatic inference.

Popular Posts

Install Ollama and Open WebUI on Ubuntu 24.04 with NVIDIA GPU Acceleration (Step-by-Step)

Install Ollama + Open WebUI on Ubuntu 24.04 with NVIDIA GPU Acceleration (Step-by-Step)

Install a Local AI Chatbot on Ubuntu 24.04 with Ollama and Open WebUI (Step-by-Step)

Trending Now

Recovering from Btrfs Boot Failures Using GUI Tools on Fedora

By the end of this guide the reader will be able to identify a Btrfs‑based Fedora installation, boot from a live USB, list and restore snapshots using the graphical utilities btrfs‑assistant and snapper, and verify that the system returns to a functional state without resorting to the command line. Understanding the Btrfs Layout Used by Fedora Fedora Workstation and Fedora KDE install the root filesystem as a single Btrfs partition that contains two default sub‑volumes. One sub‑volume holds the traditional “/” hierarchy, while the second is dedicated to /var/lib/machines . The latter exists to keep container images out of snapshot operations; it remains empty on systems that do not run virtual machines. Because Btrfs stores data in sub‑volumes rather than separate partitions, a snapshot captures the state of an entire sub‑volume at a point in time. The installer (Anaconda) automatically registers these sub‑volumes with the snapper service. Snapper maintains a series of read‑only ...