Deploy Ollama + Open WebUI on Ubuntu with GPU Acceleration using Docker Compose

Running large language models locally is now practical and fast, especially with GPU acceleration. In this tutorial, you will deploy Ollama and Open WebUI on Ubuntu 22.04/24.04 using Docker Compose. This stack gives you a private, browser-based interface for modern LLMs (Llama, Mistral, Phi, etc.) with one-click model management and secure, self-hosted inference.

Why this stack?

Ollama simplifies downloading, quantizing, and serving LLMs on your machine. Open WebUI adds a clean chat interface, prompt templates, file uploads, and multi-user access. Together, they provide a robust local AI setup that is easy to update and portable across servers.

Prerequisites

- Ubuntu Server 22.04 or 24.04 (fresh system recommended)

- An NVIDIA GPU with recent drivers (T4, RTX 20/30/40, A-series, etc.)

- sudo access and an internet connection

- Optional: a domain name for HTTPS (e.g., ai.example.com)

Step 1 — Install Docker Engine and Compose

Install Docker from the official repository to ensure up-to-date features like GPU support in 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
newgrp docker
docker --version
docker compose version

Step 2 — Enable GPU with NVIDIA Container Toolkit

Install the NVIDIA Container Toolkit to pass the GPU into containers. Verify that the host can see the GPU with nvidia-smi before proceeding.

# If you don't have drivers:
# sudo ubuntu-drivers install && sudo reboot

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/stable/deb/nvidia-container-toolkit.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 update
sudo apt install -y nvidia-container-toolkit

# Configure Docker to use the NVIDIA runtime
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

# Sanity check
nvidia-smi

Step 3 — Create the Docker Compose stack

We will run two services: Ollama (backend API on port 11434) and Open WebUI (frontend on port 3000) connected via a Docker network. The compose file also enables GPU support for Ollama.

mkdir -p ~/ollama-openwebui && cd ~/ollama-openwebui
cat > docker-compose.yml <<'YAML'
services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "11434:11434"
    volumes:
      - ollama:/root/.ollama
    gpus: all
    environment:
      - OLLAMA_KEEP_ALIVE=1h
      - OLLAMA_HOST=0.0.0.0

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

volumes:
  ollama:
  openwebui:
YAML

Step 4 — Launch and access Open WebUI

Start the stack and watch logs for any errors. The first launch will pull images.

docker compose up -d
docker compose logs -f --tail=100

Open your browser to http://SERVER_IP:3000. Create the first admin user when prompted. Open WebUI will automatically detect Ollama via the internal URL and list available models.

Step 5 — Pull a model and test

Use either the WebUI model manager or the CLI to fetch models. The example below pulls a popular 7B model.

# Pull from the host (proxies into the container)
docker exec -it ollama ollama pull llama3.1:8b

# Quick API smoke test
curl http://localhost:11434/api/generate -d '{
  "model": "llama3.1:8b",
  "prompt": "Say hello from a local LLM.",
  "stream": false
}'

In Open WebUI, select the model from the dropdown and start chatting. If you have enough VRAM, consider quantized larger models (e.g., 13B/70B Q4/Q5) for better reasoning.

Optional — Secure with a Caddy reverse proxy and HTTPS

If you have a domain, use Caddy to obtain and renew TLS automatically. This example exposes Open WebUI securely on port 443 and keeps Ollama private.

sudo apt install -y caddy
sudo tee /etc/caddy/Caddyfile >/dev/null <<'CADDY'
ai.example.com {
  encode zstd gzip
  reverse_proxy 127.0.0.1:3000
}
CADDY
sudo systemctl reload caddy

Point your DNS A/AAAA record to the server. Then visit https://ai.example.com. For teams, enable WebUI auth (already set) and create users from the admin settings.

Back up and update

To back up your models and chats, save the named volumes. You can also snapshot the folders from the host.

# Export volumes to tarballs
docker run --rm -v ollama:/v -v $(pwd):/b busybox tar czf /b/ollama-vol.tgz -C /v .
docker run --rm -v openwebui:/v -v $(pwd):/b busybox tar czf /b/openwebui-vol.tgz -C /v .

# Update images safely
docker compose pull
docker compose up -d

Troubleshooting

- No GPU detected: Ensure nvidia-smi works on the host. Re-run nvidia-ctk runtime configure, restart Docker, and verify the container sees the GPU:

docker exec -it ollama bash -lc 'nvidia-smi || ls -l /dev/nvidia*'

- Slow generation: Use quantized models (Q4_K_M/Q5_K_M), avoid oversize context windows, and confirm GPU is actually used (GPU utilization should rise in nvidia-smi during inference).

- Port conflicts: Change mapped ports in docker-compose.yml, e.g., "3001:8080" for Open WebUI or put a reverse proxy in front.

- Permission errors on volumes: Ensure your user is in the docker group and that the Docker daemon can write to the volume paths.

Security tips

- Keep Ollama bound to the internal network and only expose Open WebUI through TLS.

- Enable authentication (already set via WEBUI_AUTH=True). Use strong passwords and consider putting Open WebUI behind a VPN or SSO.

- Restrict firewall ports using UFW: allow 22/tcp and 443/tcp, then deny others.

Conclusion

You now have a GPU-accelerated, private AI stack with Ollama and Open WebUI on Ubuntu, orchestrated by Docker Compose. It is easy to upgrade, portable across servers, and suitable for personal research or team deployments. With this foundation, you can iterate quickly, evaluate new models as they drop, and keep your data fully on-prem.

Self-Host Open WebUI with Ollama on Ubuntu Using Docker Compose (GPU Optional)

Overview

This tutorial shows how to self-host Open WebUI with Ollama on Ubuntu using Docker Compose. You will get a clean, repeatable setup that runs on CPU or GPU, stores model data persistently, and can be upgraded with a single command. Open WebUI provides a modern interface, while Ollama runs local large language models such as Llama 3, Mistral, Phi-3, and CodeLlama.

Prerequisites

You will need a fresh Ubuntu 22.04 or 24.04 server (cloud VM or local machine), a user with sudo rights, and at least 8 GB of RAM. If you plan to use a GPU, an NVIDIA card is recommended. Open ports 3000 (Web UI) and 11434 (Ollama API) on your firewall or security group.

1) Install Docker and Compose

Install the official Docker Engine and the Compose plugin on Ubuntu. Log out and back in (or run newgrp) after adding your user to the docker group.

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
docker --version
docker compose version

2) Optional: Enable NVIDIA GPU Support

If you have an NVIDIA GPU, install the NVIDIA driver and the NVIDIA Container Toolkit. This lets Ollama use your GPU for faster inference.

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

After the reboot, install the container toolkit and configure 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 update
sudo apt install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Verify GPU access with Docker:

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

3) Create the Docker Compose Stack

Create a project directory and a Compose file that defines two services: Ollama (LLM runtime) and Open WebUI (frontend). The volumes preserve your models and settings across restarts.

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

Paste the following content 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=24h
    # Uncomment the next line if you have GPU configured:
    # gpus: all

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

volumes:
  ollama:
  open-webui:

4) Start the Services and Download a Model

Bring the stack online. The first start will download container images.

docker compose up -d
docker compose ps

Pull a small model to test. You can add more models later.

docker exec -it ollama ollama pull llama3.2:3b
# Other options: mistral:7b, phi3:mini, qwen2.5:7b

Open your browser to http://SERVER-IP:3000. Create your account in Open WebUI. In the model selector, choose the model you pulled and send a prompt to verify everything works.

5) Persist Data and Backups

Docker volumes keep your models and UI data under /var/lib/docker/volumes. To back them up, stop the stack and archive the data directories. This ensures quick recovery after an OS reinstall or server migration.

docker compose down
sudo tar -czf ollama_data.tgz -C /var/lib/docker/volumes \
  $(docker volume ls -q | grep "_ollama$")/_data

sudo tar -czf openwebui_data.tgz -C /var/lib/docker/volumes \
  $(docker volume ls -q | grep "_open-webui$")/_data

docker compose up -d

6) Secure and Publish (Optional)

If you expose the service on the internet, put it behind a reverse proxy with HTTPS (Caddy, Nginx, or Traefik) and set strong authentication in Open WebUI. Use a DNS name, issue a TLS certificate (Let’s Encrypt), and restrict access with IP allowlists or an identity provider. For small teams, consider running it only on a private network or VPN.

7) Update and Maintenance

Update to the newest images regularly. This pulls security updates, new UI features, and performance improvements.

cd ~/openwebui-ollama
docker compose pull
docker compose up -d

To update models to the latest quantizations or fixes, re-pull them in Ollama. You can remove old ones you no longer need.

docker exec -it ollama ollama pull mistral:7b
docker exec -it ollama ollama list
docker exec -it ollama ollama rm modelname:tag

Troubleshooting

Port already in use: Change the host port mappings in docker-compose.yml (for example, 3001:8080 or 11435:11434) and restart.

GPU not detected: Verify nvidia-smi works on the host and in a test container. Ensure the gpus: all line is uncommented and Docker was restarted after installing the NVIDIA Toolkit.

Slow or failed model pulls: Models can be large. Check disk space (df -h), network speed, and try a smaller model first. You can also mirror models by pre-downloading on another machine and copying the volume data.

Permission errors: Ensure your user is in the docker group (id) and you have logged out/in.

What You Achieved

You now have a production-friendly, self-hosted AI chat stack powered by Open WebUI and Ollama. With Docker Compose, you can start, stop, back up, and upgrade the entire setup with a couple of commands. Add or swap models as your use cases evolve—coding assistants, knowledge chat, or creative writing—while keeping your data local and under your control.

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

Overview

This tutorial shows how to self-host large language models locally by deploying Ollama and Open WebUI on Ubuntu 24.04 LTS with NVIDIA GPU acceleration using Docker Compose. Ollama handles model runtimes and downloads, while Open WebUI provides a friendly web interface, prompt management, and multi-user features. By the end, you will have a reproducible, GPU-enabled AI stack reachable from a browser on your LAN.

Prerequisites

Before you start, confirm: (1) Ubuntu 24.04 LTS installed and updated, (2) An NVIDIA GPU supported by recent drivers, (3) Administrative (sudo) access, and (4) Internet connectivity. If Secure Boot is enabled, you may need to enroll the NVIDIA kernel module signing key during driver installation.

Step 1: Prepare Ubuntu

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

Step 2: Install the NVIDIA Driver

Use Ubuntu’s built-in tool to select the correct, current driver:

ubuntu-drivers list
sudo ubuntu-drivers autoinstall
sudo reboot

After reboot, verify the GPU is recognized:

nvidia-smi

Step 3: Install Docker Engine and Compose

Add the official Docker repository and install the engine plus the Compose plugin:

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 -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER
newgrp docker

Step 4: Install NVIDIA Container Toolkit

This toolkit lets Docker containers access the GPU:

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)
curl -fsSL https://nvidia.github.io/nvidia-container-toolkit/$distribution/nvidia-container-toolkit.list | sudo tee /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

Test GPU access in a container:

docker run --rm --gpus all nvidia/cuda:12.4.1-runtime-ubuntu22.04 nvidia-smi

Step 5: Create the Docker Compose project

Make a working directory and create your Compose file:

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

Create a file named docker-compose.yaml with the following content (indentation matters):

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

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

volumes:
ollama:
openwebui:

Step 6: Launch the stack

docker compose up -d

Wait a few seconds. Visit http://localhost:3000 (or http://SERVER_IP:3000) to open Open WebUI. The first user usually becomes the admin. You can manage models from the UI or the CLI.

Step 7: Pull a model and test

Pull a model into the Ollama volume (example: Meta’s Llama 3.1 8B):

docker compose exec ollama ollama pull llama3.1

Generate a quick response from the API:

curl -s http://localhost:11434/api/generate -d '{"model":"llama3.1","prompt":"Say hello from a local GPU!","stream":false}' | jq .response

In Open WebUI, choose the model from the dropdown and start chatting.

Step 8: Use the OpenAI-compatible API

Ollama exposes an OpenAI-style API under /v1. Example with Python’s OpenAI SDK:

pip install openai
python - <<'PY'
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
resp = client.chat.completions.create(
model="llama3.1",
messages=[{"role":"user","content":"Give me a one-line fun fact."}]
)
print(resp.choices[0].message.content)
PY

Maintenance and updates

To update images without losing your data or models stored in volumes, run:

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

To update or add models, use the UI or the CLI, for example: docker compose exec ollama ollama pull mistral.

Troubleshooting

nvidia-smi fails inside containers: Ensure the NVIDIA driver is installed and matches your GPU. Reboot after installation. Confirm Docker sees the GPU with docker run --rm --gpus all nvidia/cuda:12.4.1-runtime-ubuntu22.04 nvidia-smi.

Compose “gpus” not recognized: Check your Compose plugin version with docker compose version. Update Docker packages if outdated. As a fallback, configure the NVIDIA runtime as default and remove the gpus key: sudo nvidia-ctk runtime configure --runtime=docker --set-as-default && sudo systemctl restart docker.

Slow downloads or OOM: Models are large; use a fast, stable network and ensure enough VRAM and RAM. If a model does not fit your GPU, choose a smaller variant (e.g., llama3.1:8b or a quantized build like q4_K_M).

Security tips

Bind the services to your LAN or localhost by default and place them behind a reverse proxy with TLS if exposing over the internet. In Open WebUI, enable authentication and restrict new user registration if not needed. Consider a firewall rule to limit access to ports 11434 and 3000.

Remove the stack

To stop the containers while preserving data: docker compose down. To remove everything, including downloaded models and chat history: docker compose down -v.

You now have a modern, GPU-accelerated local AI stack that is easy to manage and update. The same approach works for additional services like vector databases or reverse proxies, making it a flexible foundation for on-prem AI experiments and production prototypes.

Deploy Local LLMs on Ubuntu: Ollama + Open WebUI with Docker (GPU-Ready)

Overview

This step-by-step guide shows how to deploy a private, local AI stack on Ubuntu using Docker: Ollama for running large language models (LLMs) and Open WebUI as a fast, friendly chat interface. The setup works on CPUs and supports NVIDIA GPUs for acceleration. You will get a secure, self-hosted environment where you can run models like Llama 3.2, Phi-4, and Mistral without sending data to the cloud.

Prerequisites

- Ubuntu 22.04 or 24.04 (server or desktop)
- 16 GB RAM recommended (more for larger models), 30+ GB free disk
- Docker Engine and the Docker Compose plugin
- Optional: NVIDIA GPU with proprietary driver installed (e.g., 535+)

1) Install Docker and Docker Compose

Update your system and install Docker from the official repository for best stability and performance.

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

2) (Optional) Enable NVIDIA GPU in Containers

If you have an NVIDIA GPU, install the NVIDIA Container Toolkit so Docker can pass the GPU into containers:

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 | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#' | 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

Verify your driver with nvidia-smi. The container will get GPU access when you run it with --gpus all.

3) Create a Docker Network and Volumes

Create a dedicated network so services can talk by name and set up persistent storage:

docker network create llmnet
docker volume create ollama
docker volume create open-webui

4) Run the Ollama Container

Start Ollama. For CPU-only:

docker run -d --name ollama --restart=unless-stopped --network llmnet -p 11434:11434 -v ollama:/root/.ollama ollama/ollama:latest

With NVIDIA GPU acceleration (detected automatically):

docker run -d --name ollama --restart=unless-stopped --network llmnet --gpus all -p 11434:11434 -v ollama:/root/.ollama ollama/ollama:latest

5) Pull a Model

You can manage models from the host via docker exec. Pull a lightweight model to start quickly:

docker exec -it ollama ollama pull llama3.2:3b

Test generation from the command line:

curl http://localhost:11434/api/generate -d '{"model":"llama3.2:3b","prompt":"Say hello in one short line."}'

6) Launch Open WebUI

Open WebUI provides a clean chat interface and model manager. Start it on port 3000 and point it to the Ollama endpoint:

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

Open a browser and visit http://localhost:3000 (or your server IP). Create the first admin account, select a model (e.g., llama3.2:3b), and start chatting. If a model is missing, Open WebUI can pull it automatically via Ollama.

7) Optional: Use Docker Compose

Prefer to keep everything in a single file? Create docker-compose.yml in an empty folder and paste:

services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
     - "11434:11434"
    networks: [llmnet]
    volumes:
     - ollama:/root/.ollama
  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
    networks: [llmnet]
    volumes:
     - open-webui:/app/backend/data
networks:
  llmnet:
    external: true
volumes:
  ollama:
  open-webui:

Start with docker compose up -d. For GPU, prefer the docker run method with --gpus all, or adapt your Compose file using a GPU-capable configuration on your system.

8) Securing and Updating

- Restrict access: if running on a server, firewall ports 11434 and 3000 to trusted IPs.
- Reverse proxy: place Nginx or Caddy in front with HTTPS for remote access.
- Updates: pull newer images and recreate containers: docker pull ollama/ollama:latest && docker pull ghcr.io/open-webui/open-webui:latest, then docker stop and docker rm containers and re-run them. Your data persists in the volumes.

9) Troubleshooting

- Check logs: docker logs -f ollama and docker logs -f open-webui.
- Port in use: change published ports (e.g., -p 3001:8080).
- GPU not detected: validate nvidia-smi, reinstall the NVIDIA Container Toolkit, and ensure --gpus all is present.
- Disk space: models are large; prune unused data with docker system prune and remove models in ollama volume if needed.

10) Quick API and CLI Examples

- Pull another model: docker exec -it ollama ollama pull phi4:latest
- Chat from CLI: docker exec -it ollama ollama run mistral:7b
- Simple REST call: curl http://localhost:11434/api/generate -d '{"model":"phi4:latest","prompt":"Give me two bullet points about container security."}'

You now have a modern, private AI stack using Docker, Ollama, and Open WebUI on Ubuntu. It is fast, flexible, and ready for local development, internal knowledge assistants, and offline experimentation—no cloud required.

How to Self‑Host Open WebUI and Ollama on Ubuntu with Docker, HTTPS, and NVIDIA GPU Support

Overview

This guide shows how to self-host a private AI chatbot with Open WebUI (a clean, ChatGPT-like interface) and Ollama (for running local large language models) on Ubuntu 22.04 or 24.04. Everything runs in Docker, secured with HTTPS via Caddy and optional Basic Auth. If you have an NVIDIA GPU, you can enable GPU acceleration to speed up model inference dramatically.

What you will need

- An Ubuntu 22.04/24.04 server with at least 8 GB RAM and 20 GB free disk space. For GPU acceleration, an NVIDIA GPU with recent drivers is recommended (e.g., 8 GB VRAM or more for larger models).

- A domain name pointing to your server’s public IP (A/AAAA record). Ports 80 and 443 should be open to the internet for Let’s Encrypt.

- A non-root user with sudo privileges.

Step 1 — Install Docker and Docker Compose plugin

Update your system and install Docker 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

sudo usermod -aG docker $USER && newgrp docker

Step 2 — (Optional) Enable NVIDIA GPU for containers

Install the NVIDIA driver (if not already installed) and the NVIDIA container toolkit so Docker can access your GPU.

sudo ubuntu-drivers install (or choose a specific driver, e.g., sudo apt install -y nvidia-driver-535)

sudo reboot

Install the container toolkit:

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/stable/deb/nvidia-container-toolkit.list | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit.gpg] https://#' | 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:

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

Step 3 — Prepare Docker Compose and Caddy

Create a project folder and move into it:

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

Create a file named docker-compose.yml with the following content (replace your.domain.com later in Caddyfile):

services:
ollama:
image: ollama/ollama:latest
container_name: ollama
volumes:
- ollama:/root/.ollama
environment:
- OLLAMA_KEEP_ALIVE=2h
ports:
- "127.0.0.1:11434:11434"
restart: unless-stopped
# Uncomment the next line if you enabled NVIDIA toolkit
# gpus: all

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

caddy:
image: caddy:2
container_name: caddy
depends_on:
- openwebui
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config

volumes:
ollama:
openwebui:
caddy_data:
caddy_config:

Create a file named Caddyfile in the same folder. Replace your.domain.com with your real domain and the email with yours:

your.domain.com {
encode zstd gzip
tls [email protected]
# Optional Basic Auth — generate a hashed password below and uncomment
# basicauth {
# admin <paste_hashed_password_here>
# }
reverse_proxy openwebui:8080
}

If you want Basic Auth, generate a hash:

docker run --rm caddy:2 caddy hash-password --plaintext "StrongPassword!"

Copy the hash output, paste it into the Caddyfile under basicauth, and uncomment the lines.

Step 4 — Start the stack and pull a model

Start the services:

docker compose up -d

Pull a model with Ollama. Llama 3.1 is a great default; you can also choose smaller variants if you have less VRAM:

docker exec -it ollama ollama pull llama3.1

For low VRAM systems, try a quantized build like llama3.1:8b-instruct-q4_0 or a compact model like mistral:7b-instruct:

docker exec -it ollama ollama pull mistral:latest

Verify Ollama is up:

curl -s http://127.0.0.1:11434/api/tags

Step 5 — Access Open WebUI over HTTPS

Wait 30–60 seconds for Caddy to obtain a Let’s Encrypt certificate. Then browse to https://your.domain.com. On the first visit, create your Open WebUI admin user. In Settings > Models, select the model you pulled with Ollama. You can now chat privately with your local LLM through a friendly web interface.

Step 6 — Security hardening (recommended)

- Keep Open WebUI behind Caddy only. We already published it on localhost (127.0.0.1) to prevent direct exposure.

- Enable Basic Auth in your Caddyfile if you plan to expose the site to the open internet. Use a long, unique password.

- Restrict admin features in Open WebUI to your own account. Disable public sign-ups if you do not need them.

- Consider a firewall rule to allow inbound 80/443 only, and block 8080/11434 from the WAN.

Step 7 — Backups and updates

Back up Open WebUI data:

docker run --rm -v openwebui:/d -v $PWD:/b busybox tar czf /b/openwebui-backup.tgz -C /d .

Back up Ollama models (can be large):

docker run --rm -v ollama:/d -v $PWD:/b busybox tar czf /b/ollama-backup.tgz -C /d .

To update containers:

docker compose pull && docker compose up -d

To remove old images:

docker image prune -f

Troubleshooting

- Check logs if something fails to start: docker compose logs -f

- Verify DNS and port 80/443 reach the server; Let’s Encrypt must connect over HTTP/HTTPS the first time.

- If certificates fail, restart the stack after DNS propagates: docker compose down && docker compose up -d

- If the GPU is not detected, confirm nvidia-smi works on the host and that you added gpus: all under the Ollama service.

- Test the Ollama API locally: curl http://127.0.0.1:11434/api/generate -d '{"model":"llama3.1","prompt":"hi"}'

Where to go next

Explore model variants optimized for your hardware (Q4 for low VRAM, Q6/Q8 for higher quality, FP16 on strong GPUs). Add embeddings and RAG features in Open WebUI to chat over your documents. With this setup, you keep your data and traffic on your own server, with clean HTTPS, optional password protection, and fast local inference.

Run Local LLMs with GPU: Deploy Ollama + Open WebUI on Docker (Ubuntu 24.04)

Overview

Running large language models (LLMs) locally is easier and faster than ever with Ollama and Open WebUI. In this tutorial, you will deploy both on Docker with optional NVIDIA GPU acceleration on Ubuntu 22.04/24.04. We will cover prerequisites, the Docker Compose file, model download, security tips, updates, and troubleshooting. This guide uses simple language and SEO-friendly steps so you can get a private AI assistant running in minutes.

Prerequisites

Before you start, ensure you have: (1) Ubuntu 22.04 or 24.04 with sudo access, (2) Docker Engine and Docker Compose v2, (3) an NVIDIA GPU with proprietary drivers installed (optional but recommended), (4) at least 16 GB RAM and 20+ GB free disk for models, and (5) an open firewall port 3000 (Open WebUI) and 11434 (Ollama) if accessed remotely.

Step 0: Verify NVIDIA drivers (GPU users)

If you plan to use GPU acceleration, install the latest NVIDIA driver and verify it works. Run: nvidia-smi. You should see your GPU listed with a driver version. If the command is missing, install the driver using: sudo ubuntu-drivers autoinstall, reboot, then test nvidia-smi again.

Step 1: Install Docker Engine and Compose

Install Docker from the official repository for the best compatibility. Example quick setup:
1) sudo apt update && sudo apt install -y ca-certificates curl gnupg
2) sudo install -m 0755 -d /etc/apt/keyrings
3) curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
4) 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
5) sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
6) Optional: sudo usermod -aG docker $USER and re-login to run Docker without sudo.

Step 2: Install NVIDIA Container Toolkit (GPU users)

This step lets Docker containers access your GPU. Run:
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/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 GPU inside Docker: docker run --rm --gpus all nvidia/cuda:12.2.0-base-ubuntu22.04 nvidia-smi. If you see your GPU, you are ready.

Step 3: Create the Docker Compose file

Create a project directory, for example: mkdir -p ~/ollama-openwebui && cd ~/ollama-openwebui. Then create docker-compose.yml with the following content. This setup persists models and WebUI data, exposes ports, and enables GPU if available.

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

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

volumes:
  ollama:
  openwebui:

Notes: (a) The line gpus: "all" enables acceleration when the NVIDIA toolkit is present; Docker Compose will map this to --gpus all. (b) If you do not have a GPU, simply leave the file as-is; the Ollama image will run on CPU automatically. (c) Ports 11434 and 3000 can be changed to fit your environment or firewall rules.

Step 4: Start the stack

From the project directory, run docker compose up -d. Wait a few seconds, then confirm both containers are healthy with docker compose ps and view logs with docker logs -f ollama or docker logs -f open-webui.

Step 5: Pull a model and test

Ollama downloads models on demand. You can preload a model via the container: docker exec -it ollama ollama pull llama3.2:3b. Smaller models (2B–7B parameters) are faster and use less RAM; larger models offer higher quality but need more resources. After the pull finishes, open your browser to http://<server-ip>:3000, create your first account, and in Open WebUI select the model (for example, llama3.2:3b) to start chatting.

Step 6: Secure access

By default, Open WebUI allows signups. After creating your admin account, you can restrict access. Edit docker-compose.yml under the open-webui service and add: ENABLE_SIGNUP=false in the environment section, then run docker compose up -d again. For internet exposure, put Open WebUI behind a reverse proxy (Nginx, Caddy, or Traefik), enable HTTPS with Let’s Encrypt, and consider firewalling or a zero-trust tunnel (Cloudflare/Tailscale) for extra protection.

Maintenance and updates

To update containers without deleting your data: docker compose pull followed by docker compose up -d. To update or remove models: docker exec -it ollama ollama pull <model:tag> and docker exec -it ollama ollama rm <model:tag>. To stop the stack: docker compose down. To remove everything including volumes, add -v, but this deletes models and WebUI data.

Troubleshooting

If Open WebUI cannot see Ollama, confirm the internal URL is correct: OLLAMA_API_BASE_URL=http://ollama:11434. Check container connectivity with docker exec open-webui wget -qO- http://ollama:11434/api/tags.

If GPU is not detected, verify the NVIDIA toolkit: run docker run --rm --gpus all nvidia/cuda:12.2.0-base-ubuntu22.04 nvidia-smi. If that works but the Ollama container is still CPU-only, confirm the gpus: "all" line is present, Docker was restarted after nvidia-ctk runtime configure, and the driver version is compatible with your GPU.

If downloads are slow or interrupted, restart the Ollama container and try again. You can set an alternative registry mirror for Docker to improve pull speeds. Also verify free disk space with df -h because model files can be large.

What you achieved

You now have a private, local AI stack powered by Ollama and Open WebUI, running in Docker with persistent storage and optional GPU acceleration. This architecture is easy to back up, trivial to update, and flexible enough to host multiple models. Add a reverse proxy for TLS, schedule backups of the ollama and openwebui volumes, and explore advanced features like embedding, RAG, and function calling as you grow your setup.

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

Overview

In this step-by-step guide, you will learn how to self-host a local AI chat environment on Ubuntu using Ollama and Open WebUI. Ollama runs large language models (LLMs) locally and exposes a simple API, while Open WebUI provides a modern browser interface, chat history, and prompt management. This tutorial targets Ubuntu 22.04/24.04 and shows how to enable NVIDIA GPU acceleration, secure the service, and test the API.

Prerequisites

You need an Ubuntu 22.04/24.04 machine with at least 16 GB RAM for comfortable use and an NVIDIA GPU with recent drivers (525+ recommended) if you want hardware acceleration. For CPU-only usage, Ollama still works but will be slower. You also need a user with sudo privileges and internet access.

Step 1: Update the system and install basics

Start by refreshing your package lists and installing useful tools such as curl and ufw. Run: sudo apt update && sudo apt -y upgrade and then sudo apt -y install curl ca-certificates ufw. This ensures you have the latest security updates and a firewall ready to configure later.

Step 2: Verify NVIDIA GPU (optional but recommended)

If you intend to use GPU acceleration, confirm your NVIDIA driver installation. Run nvidia-smi. If the command shows your GPU and driver version, you are ready. If not, install a recommended driver with sudo ubuntu-drivers autoinstall, reboot using sudo reboot, and check again with nvidia-smi. Ollama includes the runtime pieces it needs and will automatically use your GPU when supported.

Step 3: Install Ollama

Ollama provides a one-line installer for Linux. Run: curl -fsSL https://ollama.com/install.sh | sh. This installs the ollama binary and sets up a systemd service called ollama. After the script completes, verify the service with systemctl status ollama. If it is not running, start it using sudo systemctl start ollama and enable it at boot with sudo systemctl enable ollama.

Step 4: Pull your first model

Ollama hosts many popular models. To start, pull a reasonably fast, high-quality base model like Meta’s Llama 3.1. Run ollama pull llama3.1. Other good options include mistral, qwen2.5, or smaller quantized variants that fit into limited VRAM (for example, llama3.1:8b or mistral:7b-instruct). Use ollama list to see installed models.

Step 5: Test the local API

Ollama listens on http://127.0.0.1:11434 by default. You can chat in the terminal with ollama run llama3.1. To test via API, run: curl http://127.0.0.1:11434/api/generate -d '{"model":"llama3.1","prompt":"Say hello from a local model."}'. You should see a streamed JSON response. Press Ctrl+C to stop streaming if needed.

Step 6: Install Docker (for Open WebUI)

Open WebUI is easiest to deploy with Docker. Install Docker and its prerequisites. First run: sudo apt -y install apt-transport-https gnupg lsb-release. Then add Docker’s repository key: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg. Add the repo: echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null. Install Docker: sudo apt update && sudo apt -y install docker-ce docker-ce-cli containerd.io. Optionally add your user to the Docker group: sudo usermod -aG docker $USER and re-login.

Step 7: Deploy Open WebUI

Open WebUI connects to Ollama’s API and provides a rich chat interface. Create a persistent volume directory and run the container pointing to the local Ollama endpoint. Use: docker run -d --name open-webui -p 3000:8080 -e OLLAMA_API_BASE_URL=http://host.docker.internal:11434 -v openwebui-data:/app/backend/data --restart unless-stopped ghcr.io/open-webui/open-webui:latest. On Linux, if host.docker.internal is not available, replace it with the host’s IP (e.g., http://127.0.0.1:11434) and add --network host instead of -p mapping if you prefer host networking: docker run -d --name open-webui --network host -e OLLAMA_API_BASE_URL=http://127.0.0.1:11434 -v openwebui-data:/app/backend/data --restart unless-stopped ghcr.io/open-webui/open-webui:latest.

Step 8: Secure optional access and firewall

If you will only use the services locally, keep them bound to localhost and do not expose ports publicly. For remote access on a trusted LAN, allow Open WebUI’s port via UFW using sudo ufw allow 3000/tcp (or none if using --network host and default port 8080). Enable the firewall with sudo ufw enable, then verify rules with sudo ufw status. For public access, place Open WebUI behind a reverse proxy (Nginx, Caddy, or Traefik) with HTTPS and authentication.

Step 9: Use the interface

Open a browser to http://SERVER_IP:3000 (or http://localhost:3000). On first load, you can create an admin account, choose your default model (e.g., llama3.1), manage prompts, and run chats. You can switch models per-conversation and configure system prompts for specific tasks like coding, summarization, or Q&A.

Troubleshooting and tips

If a model fails to load due to GPU memory limits, pull a smaller or more heavily quantized variant such as llama3.1:8b or a q4_k_m quant. If CPU usage is too high, reduce the context window or batch size in Open WebUI settings. If the Open WebUI container cannot reach Ollama, double-check OLLAMA_API_BASE_URL, networking mode, and whether the ollama service is running. For best performance on NVIDIA GPUs, close other GPU-heavy apps and monitor usage with nvidia-smi. To update, run sudo systemctl stop ollama && curl -fsSL https://ollama.com/install.sh | sh && sudo systemctl start ollama and pull newer model versions as needed.

What you have now

You have a fully local AI chat stack with GPU acceleration using Ollama and a clean, user-friendly interface via Open WebUI. It is private by default, fast on modern GPUs, and flexible with many model choices. You can integrate it with other tools via the Ollama API for scripting, automation, and offline workflows. This setup gives you control over costs, data privacy, and performance while staying current with the latest open models.

Run Open WebUI + Ollama on Docker with GPU Support (Ubuntu 24.04 Guide)

Overview

This step-by-step guide shows how to self-host Open WebUI with Ollama on Ubuntu 24.04 using Docker and persistent volumes. You will get a browser-based chat UI that talks to local large language models (LLMs), with optional NVIDIA GPU acceleration for faster inference. The setup is repeatable, easy to update, and suitable for lab, workstation, or homelab deployments.

What You’ll Build

You will deploy two containers with Docker Compose: ollama (the LLM runtime and model manager) and openwebui (the web interface). We will bind ports, persist models and settings in volumes, and optionally enable GPU. By the end, you will be able to chat with models such as llama3.1:8b directly from your browser at http://SERVER_IP:3000.

Prerequisites

- Ubuntu 22.04 or 24.04 (64-bit), a user with sudo, and a stable internet connection.
- At least 16 GB RAM recommended for 7B–8B class models; more for larger models.
- Optional NVIDIA GPU (Turing or newer) for acceleration.
- Open TCP ports 3000 (Open WebUI) and 11434 (Ollama) if accessing from other devices.

1) Optional: Install NVIDIA Drivers and Container Toolkit

Skip this section if you will run on CPU only. For GPU acceleration, install the NVIDIA driver and the NVIDIA Container Toolkit so Docker can pass the GPU to containers.

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

After the reboot, install the container toolkit and configure Docker to use it:

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

2) Install Docker Engine and Compose

Install Docker using the convenience script, then add your user to the docker group. Log out/in or run newgrp to apply the group change immediately.

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

3) Create the Docker Compose File

Create a project folder and a minimal Compose file that brings up Ollama and Open WebUI. The default snippet runs on CPU; GPU instructions are shown below.

mkdir -p ~/openwebui-ollama && cd ~/openwebui-ollama
nano docker-compose.yml
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
    # GPU (NVIDIA) - uncomment the three lines below if you have a supported GPU:
    # runtime: nvidia
    # environment:
    #   - NVIDIA_VISIBLE_DEVICES=all

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

volumes:
  ollama:
  openwebui:

Note: If your Docker setup prefers Compose's newer GPU syntax, you can replace the Ollama GPU block above with the following under the ollama service:

    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]

The "deploy" section is primarily for Swarm, but recent Docker Compose releases honor it on many setups. If it does not work, use the runtime: nvidia method instead.

4) Start the Stack

Bring the services online in the background and watch logs for a minute:

docker compose up -d
docker compose ps
docker logs -f ollama

5) Pull a Model

Use Ollama to download a model into the persistent volume. Start with an 8B class model for a good balance of quality and resource usage:

docker exec -it ollama ollama pull llama3.1:8b
# or another model:
# docker exec -it ollama ollama pull qwen2.5:7b-instruct

Once pulled, browse to http://SERVER_IP:3000. In Open WebUI, select the model in the dropdown before chatting. You can manage prompts, history, and settings from the UI.

6) Verify GPU Acceleration (Optional)

Confirm that the container sees your GPU and that inference uses it. If you enabled the GPU block and installed the toolkit, both commands should work:

docker exec -it ollama nvidia-smi
docker exec -it ollama bash -lc 'ollama run llama3.1:8b "What is the speed of light?"'

If the first command fails, re-check your driver, toolkit, and Docker runtime configuration. On CPU-only systems, skip this step.

7) Backups, Updates, and Maintenance

- Backup: the ollama volume holds your models; openwebui holds settings and history. You can back up volumes with a simple tar job:

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

- Update: pull new images and recreate containers without losing data:

docker compose pull
docker compose up -d

- Cleanup: remove unused layers and stopped containers periodically:

docker system prune -f

8) Troubleshooting Tips

Open WebUI cannot reach Ollama: Ensure OLLAMA_BASE_URL is set to http://ollama:11434 and that both services share the same compose project network (default). Restart with docker compose up -d.

GPU not detected: Confirm nvidia-smi works on the host, the NVIDIA Container Toolkit is installed, and your compose file uses either runtime: nvidia or the deploy.devices syntax. Restart Docker after configuration changes.

Out of memory or slow inference: Choose a smaller quantized model (e.g., q4 variants), increase swap on low-RAM systems, or upgrade GPU VRAM. Pulling a different tag is as simple as docker exec -it ollama ollama pull llama3.1:8b-instruct-q4_0.

Port conflicts: Change the left side of the port mappings (e.g., "11435:11434") and update your firewall or reverse proxy rules accordingly.

Security Notes

By default, these services are reachable from your network. For internet access, place them behind a reverse proxy with TLS (Nginx, Caddy, or Traefik), restrict source IPs, or expose via a secure tunnel. Avoid exposing Ollama’s port directly to the public internet.

Wrap-up

You now have a modern, local-first AI chat stack running on Docker with persistent storage and optional GPU acceleration. Add more models with ollama pull, keep images updated with docker compose pull, and back up volumes regularly. This setup scales from a developer laptop to a powerful workstation while keeping your data on your own hardware.

How to Run Local AI Models with Ollama and Open WebUI on Ubuntu (NVIDIA GPU)

Overview

This guide shows how to deploy Ollama and Open WebUI on Ubuntu so you can run large language models (LLMs) locally with NVIDIA GPU acceleration. You will install Docker and the NVIDIA Container Toolkit, run the Ollama API, connect Open WebUI as a front end, and pull a model like Llama 3. This setup is fast, private, and easy to maintain.

Prerequisites

Before you start, make sure you have: Ubuntu 22.04 or later, an NVIDIA GPU with a recent driver (525+), sudo access, internet connectivity, and open ports 11434 (Ollama) and 3000 (Open WebUI). If you have an existing Docker installation, ensure it is up to date.

1) Install NVIDIA driver and verify GPU

Install a stable NVIDIA driver from Ubuntu’s repository, reboot, and verify the GPU is visible:

sudo apt update
sudo apt install -y nvidia-driver-535
sudo reboot
# After reboot:
nvidia-smi

If nvidia-smi prints your GPU details, the driver is working. If not, check Secure Boot, which can block kernel modules; disable it or sign the modules accordingly.

2) Install Docker and enable GPU in containers

Install Docker using the official convenience script, add your user to the docker group, then install the NVIDIA Container Toolkit so containers can access the GPU.

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

# NVIDIA Container Toolkit
sudo apt update
sudo apt install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

# Verify GPU works inside Docker:
docker run --rm --gpus all nvidia/cuda:12.3.2-base-ubuntu22.04 nvidia-smi

If the last command shows GPU output, you are ready to run GPU-enabled containers.

3) Deploy Ollama (LLM runtime)

Ollama serves models locally via an HTTP API. Create a volume for persistent model storage and run the container with GPU support:

docker volume create ollama
docker run -d --name ollama --gpus all \
  -p 11434:11434 \
  -e OLLAMA_HOST=0.0.0.0:11434 \
  -v ollama:/root/.ollama \
  ollama/ollama:latest

Pull a model to test. Quantized models use less VRAM; llama3.1:8b is a good starting point on 8–12 GB GPUs.

docker exec -it ollama ollama pull llama3.1:8b
# Quick test (CLI in the container):
docker exec -it ollama ollama run llama3.1:8b

If the model loads and you can send a prompt, Ollama is ready.

4) Deploy Open WebUI (front end)

Open WebUI provides a user-friendly chat interface and features like prompt sets and file uploads. Create an isolated network, connect Ollama, and run Open WebUI:

docker network create ai
docker network connect ai ollama

docker volume create openwebui
docker run -d --name open-webui --network ai \
  -p 3000:8080 \
  -e OLLAMA_BASE_URL=http://ollama:11434 \
  -v openwebui:/app/backend/data \
  ghcr.io/open-webui/open-webui:latest

Open a browser and go to http://<server-ip>:3000. The first user to sign up becomes the administrator. After creating the admin account, open Settings and disable public signups if you want to restrict access.

5) Use your local AI

In Open WebUI, pick the model you pulled (e.g., llama3.1:8b) and start chatting. You can pull more models from the “Models” area or via:

docker exec -it ollama ollama pull mistral:7b
docker exec -it ollama ollama pull neural-chat:7b

Tip: If a model fails to load due to VRAM limits, choose a smaller or more aggressively quantized variant (e.g., Q4 or 4-bit builds).

6) Update and maintenance

To update to the latest images while keeping your data, pull and recreate the containers with the same volumes:

# Update Ollama
docker pull ollama/ollama:latest
docker stop ollama && docker rm ollama
docker run -d --name ollama --gpus all \
  -p 11434:11434 -e OLLAMA_HOST=0.0.0.0:11434 \
  -v ollama:/root/.ollama --network ai \
  ollama/ollama:latest

# Update Open WebUI
docker pull ghcr.io/open-webui/open-webui:latest
docker stop open-webui && docker rm open-webui
docker run -d --name open-webui --network ai \
  -p 3000:8080 \
  -e OLLAMA_BASE_URL=http://ollama:11434 \
  -v openwebui:/app/backend/data \
  ghcr.io/open-webui/open-webui:latest

Models and settings persist in the Docker volumes. Back up these volumes regularly with your usual server backup process.

7) Troubleshooting

If Open WebUI cannot talk to Ollama, confirm both containers share the same network and that OLLAMA_BASE_URL points to http://ollama:11434. Use docker logs open-webui to check errors.

If the GPU is not used, verify nvidia-smi inside a container works and the Docker daemon has the NVIDIA runtime configured. Also confirm you started Ollama with --gpus all. For small VRAM, prefer smaller models (e.g., 7–8B) and quantized builds.

If you see slow generation, check CPU/GPU utilization with top and nvidia-smi. Running models from SSD storage and avoiding swap helps latency. Restart long-running containers after driver updates.

What you get

With Ollama and Open WebUI on Ubuntu, you have a private, GPU-accelerated local AI stack. You can chat, summarize, and prototype apps against the Ollama API at http://<server-ip>:11434, while Open WebUI provides a polished interface for everyday use.

Deploy a Local LLM Stack: Install Ollama and Open WebUI on Ubuntu with GPU Acceleration

Running large language models locally is now practical and secure for many teams. In this guide, you will deploy a production-ready stack on Ubuntu using Ollama (for model runtime) and Open WebUI (for a clean, chat-style interface). The tutorial covers both CPU-only and NVIDIA GPU acceleration with the NVIDIA Container Toolkit, plus tips for updates, security, and backups.

Prerequisites

You need an Ubuntu 22.04 or 24.04 machine, at least 16 GB RAM for smooth performance, and optional NVIDIA GPU (Turing or newer recommended). You also need root or sudo access and a public DNS name if you plan to expose the UI securely.

Step 1: Update Ubuntu

Start by updating your system packages to ensure compatibility with recent Docker and NVIDIA components.

sudo apt update && sudo apt -y upgrade
sudo reboot

Step 2: Install Docker Engine and Compose Plugin

Install Docker from the official repository and enable the Compose plugin. This method ensures you receive timely security fixes and new features.

sudo apt -y install 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 -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER
newgrp docker

Step 3 (Optional but Recommended): NVIDIA GPU Acceleration

If you have an NVIDIA GPU, install the NVIDIA Container Toolkit to enable GPU pass-through for containers. Make sure you already have the proprietary NVIDIA driver installed (check with nvidia-smi).

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 \
  | 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 -y install nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Verify that Docker can see your GPU:

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

Step 4: Create a Docker Compose File

We will run two services: ollama (the LLM runtime and model manager) and open-webui (a modern web UI that connects to Ollama). Save the file as docker-compose.yml in an empty directory.

version: "3.8"

services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "11434:11434"
    volumes:
      - ollama:/root/.ollama
    # Uncomment the next line if you have an NVIDIA GPU:
    # gpus: all

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

volumes:
  ollama:
  openwebui:

If you are on CPU-only, keep the file as is. If you have a GPU, uncomment the gpus: all line under the ollama service.

Step 5: Launch the Stack

Start both containers in detached mode:

docker compose up -d

Open WebUI should now be available at http://<your-server-ip>:3000. The first visitor will be asked to create an admin account. Leave the browser open; we will add a model next.

Step 6: Pull and Test a Model

Pull a model using Ollama. You can choose from many OSS models; Llama 3.1 8B is a balanced starter option:

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

Confirm that the model is available:

curl http://localhost:11434/api/tags | jq

Back in Open WebUI, select this model in the top bar and start chatting. If GPU is enabled, generation should be significantly faster.

Optional: Secure Public Access with Caddy

If you want to access Open WebUI over HTTPS on a domain (for example, ai.example.com), a simple approach is to put Caddy in front. Caddy obtains and renews certificates automatically via Let’s Encrypt.

sudo apt -y install debian-keyring debian-archive-keyring apt-transport-https
curl -fsSL https://dl.cloudsmith.io/public/caddy/stable/gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/caddy-stable-archive-keyring.gpg] \
https://dl.cloudsmith.io/public/caddy/stable/deb/ubuntu all main" | \
sudo tee /etc/apt/sources.list.d/caddy-stable.list

sudo apt update && sudo apt -y install caddy

Create a simple Caddyfile that proxies traffic to Open WebUI on port 3000:

sudo bash -c 'cat >/etc/caddy/Caddyfile' << "EOF"
ai.example.com {
  reverse_proxy 127.0.0.1:3000
}
EOF
sudo systemctl reload caddy

Replace ai.example.com with your real domain and make sure DNS A/AAAA records point to your server’s public IP.

Operations: Updates, Backups, and Cleanup

Update containers regularly for new features and security patches:

docker compose pull
docker compose up -d

Backup volumes to keep models and chat history safe. Stop containers briefly, archive volumes, then restart:

docker compose down
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
docker compose up -d

Remove everything if you want to reclaim space later (this deletes models and chat data):

docker compose down
docker volume rm $(docker volume ls -q | grep -E "(ollama|openwebui)")

Troubleshooting

GPU not detected: Ensure the NVIDIA driver is installed on the host, the toolkit is configured, and your Compose service includes gpus: all. Validate with docker run --rm --gpus all nvidia/cuda:... nvidia-smi.

Permission denied: If you cannot run Docker without sudo, confirm your user is in the docker group (use id) and re-log in or run newgrp docker.

Port conflicts: If ports 3000 or 11434 are in use, change them in the Compose file and update your reverse proxy accordingly.

Low VRAM or OOM: Prefer 4–8B parameter models or quantized variants (e.g., llama3.1:8b in Q4_K_M). Ollama will automatically pick quantized builds when available.

Logs: Review service logs for errors and performance clues:

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

Why This Stack?

Ollama offers a consistent way to pull and run many open-source models locally, while Open WebUI gives you a friendly chat experience, prompt presets, file uploads, and team features. Everything stays on your hardware, which improves privacy and often reduces cost. With Docker and a reverse proxy, this setup scales from a single developer laptop to a small team server with SSL and authentication.

You now have a modern, local LLM environment with a clear upgrade path. Add more models with ollama pull, automate backups on a cron schedule, and secure public access with Caddy or another reverse proxy. For most use cases, this stack is fast, reliable, and easy to maintain.

How to Run Local AI with Ollama and Open WebUI on Docker (GPU Ready)

Overview

This step-by-step guide shows you how to deploy a private, local AI stack with Ollama (for running models) and Open WebUI (for a friendly chat interface) using Docker. You will be able to run modern language models entirely on your machine, optionally using your NVIDIA GPU for acceleration. The result is fast, offline, and secure—ideal for developers, IT teams, and privacy-focused users.

Prerequisites

- A Linux host (Ubuntu 22.04/24.04 or similar). It also works on Windows/macOS with Docker Desktop.
- Docker Engine 24+ and Docker Compose plugin.
- Open ports: 11434 (Ollama) and 3000 (Open WebUI).
- Optional GPU: recent NVIDIA driver and toolkit (CUDA-capable GPU, driver 535+ recommended).

Step 1 — Install Docker (and enable non-root use)

On Ubuntu, the fastest way is the official convenience script. Run: curl -fsSL https://get.docker.com | sh

Add your user to the docker group so you can run commands without sudo: sudo usermod -aG docker $USER then newgrp docker (or log out and back in).

Step 2 — Optional: Enable NVIDIA GPU for containers

Install the NVIDIA Container Toolkit so Docker can access your GPU: sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit

Configure it and restart Docker: sudo nvidia-ctk runtime configure --runtime=docker then sudo systemctl restart docker. Verify the GPU is visible: docker run --rm --gpus all nvidia/cuda:12.4.0-base nvidia-smi

Step 3 — Create a docker-compose.yml

In an empty folder (for example, ~/ai-stack), create a file named docker-compose.yml with the following content:

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

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

volumes:
ollama:
openwebui:

GPU acceleration (optional): if you installed the NVIDIA toolkit, add one line under the ollama service: gpus: all. For example:
ollama:
  image: ollama/ollama:latest
  gpus: all
  ...

Step 4 — Start the stack

From the same folder, run: docker compose up -d. Docker will pull images and start two containers: ollama and open-webui.

Step 5 — Pull a model in Ollama

You can pull models on demand. A good starting point is Meta’s Llama 3.2 3B (fast, small): docker exec -it ollama ollama pull llama3.2:3b

Other popular choices: phi3:mini, mistral, or qwen2.5:7b. List downloaded models with: docker exec -it ollama ollama list

Step 6 — Open the Web UI

Visit http://YOUR_SERVER_IP:3000. The first time, create an admin account. Open WebUI should auto-detect Ollama at http://ollama:11434. If not, set it under Settings → Connections → Ollama.

Start a new chat, pick the model you pulled (for example, llama3.2:3b), and send your first prompt. If you enabled GPU, generation speed should be noticeably higher.

Security and networking tips

- Keep Ollama port 11434 private. If you expose the stack to the internet, front it with a reverse proxy (Caddy, Nginx, Traefik) and enable HTTPS and authentication at the proxy layer.
- In Open WebUI, create users with least privilege and enable access controls if multiple people will connect.
- Restrict your firewall to allow only required IPs to port 3000.

Updating the stack

To update images with minimal downtime, run: docker compose pull then docker compose up -d. Your models and WebUI data live in Docker volumes and persist across updates.

Backup and restore

Backup volumes to a tarball: docker run --rm -v ollama:/data -v $PWD:/backup busybox tar czf /backup/ollama-vol.tgz -C / data and docker run --rm -v openwebui:/data -v $PWD:/backup busybox tar czf /backup/openwebui-vol.tgz -C / data

To restore, create the volumes (start the stack once), stop it, then extract the tarballs back to each volume using the same pattern.

Troubleshooting

- Permission denied on Docker: ensure your user is in the docker group (id should show docker), or prefix with sudo.
- GPU not detected: confirm nvidia-smi works on the host and that docker run --rm --gpus all nvidia/cuda:12.4.0-base nvidia-smi returns your GPU. Verify gpus: all is present in the Ollama service and restart with docker compose up -d.
- Port conflict: change 11434 or 3000 host ports in the compose file if those are already in use.
- Storage usage: models can be large. Remove models with docker exec -it ollama ollama rm MODEL_NAME and clean unused images with docker image prune.

What’s next

Add embeddings and RAG by enabling Open WebUI’s knowledge features, run multiple models in parallel, or place the stack behind a reverse proxy with a domain and TLS. With Ollama and Open WebUI on Docker, you have a fast, private, and flexible local AI platform you control.

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