Deploy a Private AI Chat Server with Ollama and Open WebUI on Ubuntu using Docker Compose (GPU Optional)

Overview

This step-by-step guide shows you how to deploy a private AI chat server on Ubuntu using Ollama and Open WebUI with Docker Compose. Ollama runs large language models (LLMs) locally, while Open WebUI gives you a clean web interface for chat, prompts, and model management. The setup works on CPUs and can optionally use an NVIDIA GPU for much faster inference. You will learn installation, configuration, GPU enablement, security basics, updates, and backup tips.

Prerequisites

Before you start, make sure you have: (1) Ubuntu 22.04/24.04 or another recent Linux distro, (2) sudo access, (3) at least 8 GB of RAM (more is better), (4) 20+ GB of free disk space for models, (5) Docker Engine and the Docker Compose plugin, and optionally (6) an NVIDIA GPU with drivers and the NVIDIA Container Toolkit if you want acceleration.

Step 1: Install Docker and Compose

Install Docker Engine and Compose using the official repository. If you already have Docker, you can skip to the next step.

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 2: Create the Docker Compose project

Create a working directory and a Docker Compose file that launches two services: ollama (the model runtime and API) and open-webui (the frontend). This configuration stores models in a named volume and exposes the web UI on port 3000. The GPU configuration is included and can be left in place even if you are on CPU-only; it will be ignored without an NVIDIA setup.

mkdir -p ~/ollama-openwebui
cd ~/ollama-openwebui
nano docker-compose.yml
services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "11434:11434"
    volumes:
      - ollama-data:/root/.ollama
    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
    depends_on:
      - ollama
    environment:
      - OLLAMA_API_BASE=http://ollama:11434
      - WEBUI_NAME=Private AI Chat
      - ENABLE_SIGNUP=true
    ports:
      - "3000:8080"
    volumes:
      - openwebui-data:/app/backend/data

volumes:
  ollama-data:
  openwebui-data:

Step 3: Start the stack and pull a model

Bring the services up in the background and open the web UI at http://SERVER_IP:3000. The first load may take a moment.

docker compose up -d

You can pull models from the UI (Models menu) or via the CLI. For example, to fetch a good general model:

docker exec -it ollama ollama pull llama3.1
# Other options: mistral, phi3, qwen2, codellama, llama3.1:8b-instruct-q4_K_M

In Open WebUI, select your model from the dropdown, then start chatting. You can also adjust system prompts, temperature, and context length from the settings.

Step 4: Enable GPU acceleration (optional)

To use an NVIDIA GPU, install the driver and the NVIDIA Container Toolkit, then restart Docker. Your Compose file above already includes GPU reservations; Docker will attach GPUs automatically when available.

# Install NVIDIA driver (check your GPU support docs)
sudo apt-get install -y nvidia-driver-535

# Install NVIDIA Container Toolkit
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-get update
sudo apt-get install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

# Recreate containers
docker compose up -d --force-recreate

Verify GPU is visible:

docker exec -it ollama nvidia-smi

Step 5: Secure access

By default, the web UI is open to anyone who can reach the server. For small teams, keep the service bound to your private network, enable signups only for trusted users, and set an admin email with environment variables in the Open WebUI service. For internet exposure, place NGINX or Caddy in front with HTTPS and basic auth or OIDC. A quick alternative is to keep port 3000 closed publicly and use an SSH tunnel: ssh -L 3000:localhost:3000 user@server.

Step 6: Update and backup

To update to the latest versions, pull new images and recreate containers without losing data:

docker compose pull
docker compose up -d

Back up your volumes regularly. They contain downloaded models and user data. You can snapshot them to a tar archive:

docker run --rm -v ollama-openwebui_ollama-data:/data -v $PWD:/backup alpine \
  tar -czf /backup/ollama-data.tgz -C /data .
docker run --rm -v ollama-openwebui_openwebui-data:/data -v $PWD:/backup alpine \
  tar -czf /backup/openwebui-data.tgz -C /data .

Troubleshooting tips

If models do not load, check logs: docker logs -f ollama and docker logs -f open-webui. For out-of-memory errors, choose a smaller model variant (e.g., 7B/8B quantized). If GPU is not detected, ensure the driver and toolkit versions match, verify nvidia-smi works on the host, and recreate containers. Slow responses on CPU are normal; try quantized models (like Q4_K_M) for better speed and lower RAM. To change the web UI name, edit WEBUI_NAME and run docker compose up -d.

What you achieved

You now have a private AI chat server running locally with Docker. Ollama hosts your LLMs, Open WebUI provides a friendly interface, and optional NVIDIA acceleration boosts performance. With updates and backups in place, you can safely iterate, add specialized models for code or documents, and keep your AI workflows under your control.

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

Running a fast, private AI chatbot on your own computer or server is easier than ever. In this guide, you will install Ollama (a lightweight local LLM runtime) and Open WebUI (a modern web interface) on Ubuntu 24.04. You will be able to chat with models like Llama 3 or Mistral without sending data to the cloud, and with optional GPU acceleration if you have an NVIDIA card.

What you will need: an Ubuntu 22.04/24.04 machine (VM, bare metal, or WSL), at least 8 GB RAM (16 GB recommended for larger models), 15–30 GB free disk space for models, Internet access, and optional NVIDIA GPU drivers for acceleration.

Why Ollama + Open WebUI?

Ollama manages local large language models (LLMs) with simple commands and sensible defaults. Open WebUI gives you a clean, chat-style interface with features like prompt history, file uploads (for some models), and model switching. Together, they are a simple, reliable stack for a self-hosted AI experience.

1) Update Ubuntu and install basics

First, refresh your package list and install required tools:

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

2) Install Ollama and start the service

Ollama provides an installer script for Linux. Run the following to install and start the service:

curl -fsSL https://ollama.com/install.sh | sh
sudo systemctl enable --now ollama

Verify that the Ollama API is listening on port 11434:

ss -tulpn | grep 11434

3) Pull a model (Llama 3 as an example)

Ollama hosts a registry of optimized models. Pull a popular general-purpose model such as Llama 3 8B:

ollama pull llama3:8b

After the download completes, you can test it quickly:

ollama run llama3:8b

Type a prompt and press Enter. Press Ctrl+C to exit.

4) Install Docker and run Open WebUI

Open WebUI is easiest to deploy with Docker. Install Docker using the official convenience script, then start the container:

curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER # log out/in after this

Run Open WebUI and connect it to your local Ollama service:

docker run -d --name open-webui \
-p 3000:8080 \
-e OLLAMA_BASE_URL=http://127.0.0.1:11434 \
-v open-webui:/app/backend/data \
--restart unless-stopped \
ghcr.io/open-webui/open-webui:latest

Open your browser and go to http://SERVER_IP:3000. On first access you will create an admin account. Then choose your default model (e.g., llama3:8b) from the interface and start chatting.

5) Enable GPU acceleration (optional, NVIDIA)

If your machine has an NVIDIA GPU, install the official driver from Ubuntu’s Additional Drivers or with sudo apt install nvidia-driver-XXX (replace XXX with a recommended version). Reboot and verify with nvidia-smi. Ollama will auto-detect CUDA and use your GPU for supported models, delivering much faster responses. You do not need GPU pass-through to Docker for this setup because Ollama runs on the host.

6) Secure and harden your deployment

Local-only binding: If you are on a public server, avoid exposing the UI directly. Bind Open WebUI to localhost and place a reverse proxy with HTTPS in front:

docker rm -f open-webui
docker run -d --name open-webui \
-p 127.0.0.1:3000:8080 \
-e OLLAMA_BASE_URL=http://127.0.0.1:11434 \
-v open-webui:/app/backend/data \
--restart unless-stopped \
ghcr.io/open-webui/open-webui:latest

Reverse proxy tip: Use any TLS-capable proxy (Nginx, Caddy, Traefik). For example, with Caddy you can map your domain to localhost:3000 and get automatic HTTPS. Protect access using password auth or your proxy’s single sign-on.

7) Daily use and model management

Switch models in the Open WebUI sidebar or pull additional ones via Ollama. Useful commands:

# list local models
ollama list

# pull a different model
ollama pull mistral:7b

# remove unused models to free space
ollama rm model_name

When you click “New Chat” in Open WebUI, you can choose the model and adjust temperature, system prompt, and other parameters. For tasks like coding or reasoning, try llama3.1 or mistral-nemo variants if available for your hardware.

8) Updating the stack

Keep components fresh to get speed and quality improvements:

# update Ollama binary
curl -fsSL https://ollama.com/install.sh | sh
sudo systemctl restart ollama

# update Open WebUI container
docker pull ghcr.io/open-webui/open-webui:latest
docker stop open-webui && docker rm open-webui
docker run ... (same command as before)

9) Troubleshooting common issues

Port conflicts: If 11434 or 3000 is already in use, pick a different host port (for example, -p 8081:8080 for Open WebUI). Check usage with ss -tulpn.

Insufficient VRAM or RAM: Large models may fail to load. Try a smaller variant (e.g., llama3:8b instead of 70b), or use quantized builds where available.

No GPU detected: Ensure the NVIDIA driver is installed and loaded (nvidia-smi works). Reboot after driver installation. Ollama falls back to CPU if no GPU is available.

Docker permissions: If you see “permission denied,” log out and back in after adding your user to the docker group, or run commands with sudo.

Disk space: Models can be large. Use ollama list and ollama rm to remove what you do not need. Check usage with df -h.

10) What’s next?

Explore prompt templates, create system prompts for repeatable tasks, and try specialized models for coding, document Q&A, or SQL. You can also connect Open WebUI to external tools, set up team access behind your company SSO, or run multiple instances for different workloads. With Ollama and Open WebUI, you have a fast, private, and extensible foundation for local generative AI on Ubuntu.

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 ...