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.

How to Install Ollama and Open WebUI on Ubuntu 24.04 (with Optional GPU Acceleration)

Overview

This step-by-step guide shows how to run open-source large language models (LLMs) locally on Ubuntu 24.04 using Ollama for model serving and Open WebUI for a friendly chat interface. You will install Ollama, enable optional GPU acceleration (NVIDIA or CPU fallback), and deploy Open WebUI with Docker. The result is a private, fast, and controllable AI setup suitable for home labs and small teams.

Prerequisites

You need an Ubuntu 24.04 LTS host with internet access, a user with sudo rights, and at least 8 GB of RAM. A modern NVIDIA GPU is optional but recommended for faster inference. Make sure the system is up to date: sudo apt update && sudo apt -y upgrade

Step 1 — Install Ollama

Ollama is a lightweight server that downloads and runs models locally. Install it with the official script:
curl -fsSL https://ollama.com/install.sh | sh

Enable and start the service so it runs at boot:
sudo systemctl enable ollama
sudo systemctl start ollama
sudo systemctl status ollama

Verify the API is listening on port 11434:
curl http://127.0.0.1:11434/api/tags

Step 2 — Optional: Enable GPU Acceleration (NVIDIA)

If you have an NVIDIA GPU, install the recommended driver. Ubuntu makes this easy:
sudo ubuntu-drivers autoinstall
sudo reboot

After reboot, confirm the driver is active:
nvidia-smi

Ollama detects GPUs automatically when drivers are present. No extra flags are required. If you need to force CPU or GPU behavior, you can set:
export OLLAMA_NO_GPU=1 (CPU only) or export OLLAMA_NO_GPU=0 (GPU allowed). For a persistent setting, add the variable to your shell profile and restart Ollama:
sudo systemctl restart ollama

AMD GPUs can work with ROCm on supported cards and drivers. If you are using AMD, install the ROCm runtime from AMD’s repository for Ubuntu 24.04, confirm with rocminfo, and ensure your user is in the video and render groups. If ROCm is not available for your hardware, Ollama will fall back to CPU.

Step 3 — Pull a Model and Test Locally

Pull a well-supported model. Llama 3 is a popular choice:
ollama pull llama3

Run a quick test:
ollama run llama3 "Write one sentence about Ubuntu 24.04."

Tip: For smaller footprints, choose tiny models like llama3:8b or phi3. VRAM needs vary; an 8B model typically benefits from 8–12 GB of GPU VRAM, while CPU-only runs need more system RAM and patience.

Step 4 — Install Docker and Open WebUI

Open WebUI gives you a clean browser interface for Ollama. Install Docker from Ubuntu repos for a quick start:
sudo apt install -y docker.io docker-compose-plugin

Allow your user to manage Docker without sudo, then re-login:
sudo usermod -aG docker $USER

Create a persistent volume for Open WebUI data and start the container. It will connect to Ollama on the host:
docker volume create openwebui
docker run -d --name open-webui -p 3000:8080 --restart unless-stopped -e OLLAMA_BASE_URL=http://127.0.0.1:11434 -v openwebui:/app/backend/data ghcr.io/open-webui/open-webui:latest

Open your browser to http://SERVER_IP:3000 and complete the initial admin setup. Add a model in Settings if it does not appear automatically, for example llama3.

Step 5 — Optional TLS with Caddy (Automatic HTTPS)

If you have a domain pointing to your server (A record), Caddy can auto-provision HTTPS certificates. Install it and configure a simple reverse proxy:
sudo apt install -y caddy

Edit /etc/caddy/Caddyfile (replace ai.example.com with your domain):
ai.example.com {
  reverse_proxy 127.0.0.1:3000
}

Reload Caddy:
sudo systemctl reload caddy. Visit https://ai.example.com. Ensure ports 80 and 443 are open on your firewall and router.

Step 6 — Backups and Updates

Ollama models are stored under ~/.ollama for non-root users or /usr/share/ollama when installed system-wide. Back up this directory to avoid re-downloading models. Example:
tar czf ollama-backup.tgz ~/.ollama

Open WebUI data is in the Docker volume openwebui. Back it up with:
docker run --rm -v openwebui:/data -v $(pwd):/backup alpine sh -c "cd /data && tar czf /backup/openwebui-backup.tgz ."

To update Ollama:
curl -fsSL https://ollama.com/install.sh | sh && sudo systemctl restart ollama. To update Open WebUI:
docker pull ghcr.io/open-webui/open-webui:latest && docker stop open-webui && docker rm open-webui && docker run ... (re-run the previous docker run command).

Troubleshooting

If port 11434 or 3000 is in use, change the port in the docker run command or stop the conflicting service. For slow responses, try a smaller model or ensure your GPU driver is working. If Open WebUI cannot reach Ollama, verify curl http://127.0.0.1:11434/api/tags succeeds on the host and confirm the OLLAMA_BASE_URL is correct.

Wrap-up

You now have a private AI stack on Ubuntu 24.04 with Ollama handling model inference and Open WebUI offering a clean chat interface. With optional GPU acceleration, HTTPS, and simple backups, this setup is fast, secure, and maintainable—perfect for learning, prototyping, or running an internal assistant.

Run a Local AI Chatbot with Ollama and Open WebUI on Ubuntu (GPU + Docker)

Local large language models are now practical on a single server. In this step-by-step guide, you will deploy a private AI chatbot by running Ollama (for models) and Open WebUI (for the user interface) on Ubuntu using Docker. We will enable GPU acceleration with NVIDIA so responses are fast and efficient. By the end, you will have a persistent setup that survives reboots and is easy to update.

Overview

Ollama is a lightweight runtime that downloads and serves popular open-source models like Llama 3. Open WebUI is a web app that connects to Ollama and provides a clean chat interface, prompt templates, conversation history, and model management. We will run both components in Docker containers on the same Docker network and map persistent volumes for data. Optional GPU acceleration uses the NVIDIA Container Toolkit.

Prerequisites

- Ubuntu Server or Desktop (22.04 or 24.04 recommended)
- An NVIDIA GPU with proprietary drivers installed (verify with nvidia-smi) if you want GPU acceleration; CPU-only also works
- Sudo access and outbound internet connectivity
- Basic command line familiarity

1) Install Docker Engine and Compose

Install the official Docker packages and add your user to the docker group for passwordless usage.

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

2) Enable NVIDIA GPUs in Docker (optional but recommended)

If you have an NVIDIA GPU and drivers are installed, add the NVIDIA Container Toolkit so Docker can access the GPU. Verify drivers first with nvidia-smi. Then install the toolkit 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-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-get update
sudo apt-get install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Test compute visibility by running a CUDA-enabled container (optional):

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

3) Create a Docker network and persistent volumes

We will create an isolated network for both containers and define persistent volumes so model files and WebUI data survive restarts.

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

4) Run Ollama (model server)

Start the Ollama container. If you have a GPU, include --gpus all. The port 11434 is the Ollama API.

# GPU-enabled
docker run -d --name ollama --gpus all --restart unless-stopped \
  -p 11434:11434 \
  -v ollama:/root/.ollama \
  --network ollama-net \
  ollama/ollama:latest

# CPU-only (if you do not have an NVIDIA GPU)
# docker run -d --name ollama --restart unless-stopped \
#   -p 11434:11434 \
#   -v ollama:/root/.ollama \
#   --network ollama-net \
#   ollama/ollama:latest

Pull a model and do a quick test inside the container. Llama 3 and Qwen are great starting options.

docker exec -it ollama ollama pull llama3.1:8b
docker exec -it ollama ollama run llama3.1:8b "Write a two-line poem about local AI."

5) Run Open WebUI (front-end)

Open WebUI connects to the Ollama API. On first launch it creates an admin account when you sign in. We will point it at Ollama via the internal Docker network name.

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

Open a browser to http://<server-ip>:3000. Create your account, select the model you pulled (for example, llama3.1:8b), and start chatting. You can pull additional models anytime using docker exec -it ollama ollama pull qwen2.5:7b and select them in Open WebUI.

6) Optional: Use Docker Compose instead of docker run

If you prefer a single file, create docker-compose.yml in an empty folder. The gpus: all key enables GPU acceleration when the NVIDIA toolkit is installed.

services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "11434:11434"
    volumes:
      - ollama:/root/.ollama
    networks:
      - ollama-net
    deploy:
      resources:
        reservations:
          devices:
            - capabilities: ["gpu"]
    # Alternatively for Compose v2+:
    # 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
    volumes:
      - open-webui:/app/backend/data
    networks:
      - ollama-net

volumes:
  ollama:
  open-webui:

networks:
  ollama-net:
    external: true

Then run:

docker network create ollama-net
docker compose up -d

7) Updating and maintenance

To update images, pull the latest versions and recreate the containers. Your data and models remain in volumes.

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 (or docker compose up -d)

To see logs for troubleshooting, run docker logs -f ollama and docker logs -f open-webui. If the WebUI cannot see models, ensure the environment variable OLLAMA_BASE_URL points to http://ollama:11434 and both containers share the same Docker network.

Troubleshooting tips

GPU not detected: Confirm the NVIDIA driver works on the host (nvidia-smi), the NVIDIA Container Toolkit is installed, and the container uses --gpus all. If using Compose, ensure gpus: all or the device reservation is defined.

Ports already in use: Change host ports in the run commands (for example, map Open WebUI to -p 8080:8080 instead of 3000).

Slow downloads or storage limits: Models are large. Consider attaching a larger Docker volume or moving /var/lib/docker to a disk with more space. You can also choose smaller models (7B) or quantized variants.

HTTPS and access control: Put Open WebUI behind a reverse proxy such as Nginx or Caddy with HTTPS and firewall rules. For internet exposure, add authentication, rate limits, and consider a VPN or zero-trust tunnel.

What you built

You now have a local, private AI chatbot with GPU acceleration on Ubuntu using Docker. Ollama handles model serving, while Open WebUI gives you a friendly interface with history, prompts, and multi-model management. This setup is repeatable, easy to update, and keeps your data on your own hardware.

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.

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.

Run Your Own Local AI Chat: Ollama + Open WebUI on Docker with NVIDIA or AMD GPU Acceleration

Overview

Running a private AI assistant on your own machine is now practical, fast, and secure. In this step-by-step guide, you will deploy Ollama (to run large language models locally) and Open WebUI (a clean chat interface) using Docker. The tutorial covers CPU-only mode and GPU acceleration with both NVIDIA and AMD ROCm, so you get the best performance out of your hardware. By the end, you will have a persistent setup that auto-starts on boot, supports one-click model management, and is easy to update.

Prerequisites

- A 64-bit Linux host (Ubuntu 22.04+ recommended) with internet access.
- Docker Engine installed and running.
- For NVIDIA GPUs: proprietary drivers and the NVIDIA Container Toolkit.
- For AMD GPUs: ROCm-capable GPU with ROCm drivers (5.7+).
- Open ports 11434 (Ollama API) and 3000 (Open WebUI). You can change ports if they collide with other services.

Step 1 — Install Docker (Ubuntu quick method)

If Docker is not installed, run:

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

Step 2 — Enable GPU in Docker (optional but recommended)

NVIDIA: Install the NVIDIA driver and container toolkit, then restart Docker:

sudo apt-get install -y nvidia-driver-535 (or newer)
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 -s -L 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-get update && sudo apt-get install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker && sudo systemctl restart docker

AMD ROCm: Install ROCm drivers appropriate for your GPU. Ensure devices /dev/kfd and /dev/dri exist. No extra Docker runtime is needed; you will pass devices to the container.

Step 3 — Create a dedicated Docker network

Create a private bridge network so containers can discover each other by name:

docker network create ai

Step 4 — Start Ollama (choose one)

NVIDIA GPU:

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

AMD ROCm GPU:

docker run -d --name ollama --device /dev/kfd --device /dev/dri --group-add video --ipc=host --restart unless-stopped --network ai -p 11434:11434 -v ollama:/root/.ollama ollama/ollama:rocm

CPU-only:

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

Step 5 — Start Open WebUI and connect it to Ollama

Run Open WebUI on port 3000 and point it at the Ollama API using the container name:

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

Open a browser and visit http://YOUR_SERVER_IP:3000. On first launch, create your admin account. In Settings, disable public sign-ups if this instance is exposed to untrusted networks.

Step 6 — Download a model and chat

You can pull models from Open WebUI’s UI. Or pull via CLI:

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

For lower VRAM, try quantized variants (for example: llama3.1:8b-instruct-q4_0). After the download completes, select the model in Open WebUI and start chatting locally.

Security and access tips

- Keep ports private if possible; bind to localhost and use an authenticated reverse proxy (Nginx, Caddy, or Traefik) if exposing to the internet.
- Regularly update images and disable open registration in Open WebUI.
- Use Docker volumes (already configured) to persist models and settings across updates.

Updating to the latest versions

docker pull ollama/ollama:latest (or ollama/ollama:rocm for AMD)
docker pull open-webui/open-webui:latest
docker stop open-webui ollama && docker rm open-webui ollama
Re-run the docker run commands from Steps 4–5. Your data persists in volumes.

Troubleshooting

- GPU not detected (NVIDIA): test with docker run --rm --gpus all nvidia/cuda:12.3.2-base-ubuntu22.04 nvidia-smi.
- GPU not detected (AMD): ensure /dev/kfd and /dev/dri exist and your user is in the video group (the container already adds it).
- Slow or failed model pulls: check DNS/proxy and rerun the pull. Try a smaller or more quantized model.
- Port conflicts: change -p 11434:11434 or -p 3000:8080 to other free host ports.

Uninstall and cleanup

docker rm -f open-webui ollama
docker volume rm open-webui ollama
docker network rm ai

You now have a flexible, private AI stack that runs entirely on your machine. Swap models as needed, tune quantization for your hardware, and keep your data under your control.

3.

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.

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.

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.

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

Overview

This guide shows you how to install Ollama and Open WebUI on Ubuntu 24.04 with NVIDIA GPU acceleration. You will get a fast local AI stack that can run modern large language models (LLMs) like Llama 3 on your own hardware, secured and accessible in a web browser. We will cover GPU driver setup, Docker with the NVIDIA Container Toolkit, Ollama installation, Open WebUI deployment, basic security, and troubleshooting.

Prerequisites

- A machine running Ubuntu 24.04 (fresh or updated).
- An NVIDIA GPU with at least 8 GB VRAM recommended for 8B models (more is better).
- Internet access and sudo privileges.

Step 1: Install the NVIDIA GPU Driver

Install the recommended proprietary driver so CUDA becomes available to both Ollama and containers.

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

After reboot, verify the GPU is recognized:

nvidia-smi

You should see a driver version and your GPU model. If not, check “Troubleshooting.”

Step 2: Install Docker and the NVIDIA Container Toolkit

We will run Open WebUI in Docker and connect it to the host’s Ollama API. First, install Docker Engine from the official repository:

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

Now install the NVIDIA Container Toolkit so containers can access your 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
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Quick GPU-in-container test (optional):

docker run --rm --gpus all nvidia/cuda:12.6.2-base-ubuntu24.04 nvidia-smi

Step 3: Install Ollama (GPU-Accelerated LLM Runtime)

Ollama downloads, runs, and serves models locally. The installer sets up a system service by default.

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

Verify the API is listening on port 11434:

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

Check GPU visibility and the model directory:

ollama info

Note: On Ubuntu, the Ollama service runs as the “ollama” user. Models are typically stored under /usr/share/ollama (service) or ~/.ollama (when run as your user). The exact location appears in ollama info.

Step 4: Deploy Open WebUI (Docker)

Open WebUI provides a friendly browser UI that connects to Ollama’s API. We’ll run it in host networking mode so it can reach 127.0.0.1:11434 directly.

docker run -d --name open-webui --restart unless-stopped --network=host -e OLLAMA_BASE_URL=http://127.0.0.1:11434 ghcr.io/open-webui/open-webui:latest

Open your browser and visit http://<server-ip>:8080. On first launch, create the admin account. In Settings, confirm the Ollama endpoint is http://127.0.0.1:11434.

Step 5: Pull a Model and Test

Download a model with good quality/speed balance. The 8B variants work well on many consumer GPUs.

ollama pull llama3.1:8b

Quick API test:

curl http://127.0.0.1:11434/api/generate -d '{"model":"llama3.1:8b","prompt":"Say hello in one short sentence."}'

Or try the CLI:

ollama run llama3.1:8b "Explain the difference between VRAM and system RAM in one paragraph."

You should see GPU utilization in nvidia-smi while the model is generating.

Step 6: Basic Security and Management

If your server is exposed to a network, restrict Open WebUI to trusted IPs with UFW (replace the subnet with your LAN):

sudo apt install -y ufw
sudo ufw allow OpenSSH
sudo ufw allow from 192.168.0.0/16 to any port 8080 proto tcp
sudo ufw enable

Keep your stack up to date:

sudo systemctl stop ollama && curl -fsSL https://ollama.com/install.sh | sh && sudo systemctl start ollama
docker pull ghcr.io/open-webui/open-webui:latest && docker restart open-webui

To persist Open WebUI data, mount a volume (recommended for production):

docker run -d --name open-webui --restart unless-stopped --network=host -v /opt/open-webui:/app/backend/data -e OLLAMA_BASE_URL=http://127.0.0.1:11434 ghcr.io/open-webui/open-webui:latest

Troubleshooting

nvidia-smi: command not found or no devices were found
- Reinstall drivers: sudo ubuntu-drivers autoinstall and reboot.
- If Secure Boot is enabled, you may need to enroll the NVIDIA kernel module (MOK) or temporarily disable Secure Boot in firmware.
- Use a supported driver (typically 535+ on newer GPUs).

Docker can’t see the GPU
- Test: docker run --rm --gpus all nvidia/cuda:12.6.2-base-ubuntu24.04 nvidia-smi.
- Reconfigure toolkit: sudo nvidia-ctk runtime configure --runtime=docker && sudo systemctl restart docker.
- Ensure you’re using the NVIDIA proprietary driver, not Nouveau.

Open WebUI cannot connect to Ollama
- Confirm Ollama API is running: curl http://127.0.0.1:11434/api/tags.
- Check logs: docker logs -f open-webui.
- Ensure --network=host is used and OLLAMA_BASE_URL is set to http://127.0.0.1:11434.

Models consume too much VRAM
- Try a smaller quantization (e.g., llama3.1:8b default Q4_K_M) or use a 7B/8B model instead of 13B/70B.
- Limit parallel requests in Open WebUI settings and Ollama.

What You Built

You now have a local, GPU-accelerated AI environment with Ollama serving LLMs and Open WebUI providing a clean chat interface. This setup is fast, private, and easy to maintain, giving you full control over your models and data. You can add more models with ollama pull, create prompt presets in Open WebUI, and secure access with firewalls or a reverse proxy if you plan to expose it beyond your LAN.

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.

Run a Private AI Chat with Ollama and Open WebUI on Docker (CPU/GPU): Step-by-Step Guide

Overview

This tutorial shows you how to deploy a private AI chatbot using Ollama and Open WebUI with Docker on Linux (Ubuntu 22.04/24.04). You will get a secure, local, and fast setup that can run on CPU or use your NVIDIA GPU for acceleration. We will cover installation, model downloads, persistence, updates, and security hardening.

What You Will Build

- Ollama container serving large language models (LLMs) on port 11434.
- Open WebUI container providing a modern chat interface on port 3000.
- Optional NVIDIA GPU pass-through for faster inference.
- Persistent volumes so your models and settings survive reboots and updates.
- Basic authentication and reverse proxy tips for safe remote access.

Prerequisites

- A 64-bit Linux host with Docker Engine installed. On Ubuntu, install Docker with:
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
sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- Optional: an NVIDIA GPU with drivers installed (530+ recommended) if you want GPU acceleration.

Optional: Enable NVIDIA GPU for Docker

If you have an NVIDIA GPU, 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
sudo apt update && sudo apt install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker
Test with:
docker run --rm --gpus all nvidia/cuda:12.2.0-base-ubuntu22.04 nvidia-smi

Create Folders and a Dedicated Network

mkdir -p ~/ai/ollama ~/ai/openwebui
docker network create ai-net

Start the Ollama Container (CPU or GPU)

CPU-only (works everywhere):
docker run -d --name ollama --restart unless-stopped \
-p 11434:11434 \
-v ~/ai/ollama:/root/.ollama \
--network ai-net \
ollama/ollama:latest

GPU-enabled (if you completed the NVIDIA step):
docker run -d --name ollama --restart unless-stopped \
-p 11434:11434 \
-v ~/ai/ollama:/root/.ollama \
--gpus all \
--network ai-net \
ollama/ollama:latest

Pull a Model with Ollama

Ollama hosts many models (Llama 3, Phi-3, Mistral, Gemma, etc.). Pull one that fits your hardware. For a good balance, try Llama 3 8B:
docker exec -it ollama ollama pull llama3:8b
On low-memory machines, use a smaller or quantized model (for example llama3:8b-instruct-q4_K_M). You can list models with:
docker exec -it ollama ollama list

Start Open WebUI and Connect It to Ollama

Run Open WebUI with persistent storage and authentication. Replace the admin email and password before running:
docker run -d --name openwebui --restart unless-stopped \
-p 3000:8080 \
-e OLLAMA_BASE_URL=http://ollama:11434 \
-e WEBUI_AUTH=True \
-e [email protected] \
-e ADMIN_PASSWORD='ChangeThisStrongPass!2025' \
-v ~/ai/openwebui:/app/backend/data \
--network ai-net \
ghcr.io/open-webui/open-webui:latest

Now open your browser and go to http://SERVER_IP:3000. Log in with the admin account. In the model dropdown, select the model you pulled (for example llama3:8b) and start chatting.

Persist and Back Up Your Data

All models and settings are stored in the bind mounts we created:
- Models and Ollama config: ~/ai/ollama
- Web interface data (users, chats): ~/ai/openwebui
To back them up, stop containers and archive the folders:
docker stop openwebui ollama
tar -czf ai-backup-$(date +%F).tar.gz -C ~/ ai
docker start ollama openwebui

Update Containers and Models

To update to the latest versions safely:
docker pull ollama/ollama:latest
docker pull ghcr.io/open-webui/open-webui:latest
docker stop openwebui ollama
docker rm openwebui ollama
Recreate with the same docker run commands (volumes keep your data). To update a model:
docker exec -it ollama ollama pull llama3:8b

Secure Remote Access

- Keep WEBUI_AUTH=True and use a strong admin password.
- Restrict firewall: allow only your IP and necessary ports (11434, 3000, or the reverse proxy port). On Ubuntu with UFW:
sudo ufw allow 22/tcp
sudo ufw allow from YOUR.IP.ADDR.0/24 to any port 3000 proto tcp
sudo ufw enable
- For HTTPS, place a reverse proxy in front. Example Caddyfile (replace domain):
ai.example.com {
  reverse_proxy 127.0.0.1:3000
}
Caddy will auto-issue TLS certificates via Let’s Encrypt.

Performance Tips

- Prefer GPU for large models. Use smaller or quantized models on CPU-only hosts.
- Set the context window and temperature in Open WebUI for faster, more focused responses.
- Avoid swapping: ensure available RAM; 8–16 GB is reasonable for 7–8B quantized models, more for FP16 and larger models.
- Pin container CPU/RAM if needed using --cpus and -m flags in docker run.

Troubleshooting

- Port already in use: change -p 3000:8080 or stop the conflicting service.
- GPU not detected: confirm nvidia-smi works on the host, verify nvidia-ctk runtime configure, restart Docker, and run the CUDA test container.
- Model download slow: it is normal on first pull; try a different model or check your network.
- Open WebUI cannot reach Ollama: ensure both containers are on ai-net and OLLAMA_BASE_URL=http://ollama:11434 is set correctly.

Conclusion

With Docker, Ollama, and Open WebUI, you can run a private AI chat system that is fast, flexible, and secure. This stack supports many modern open models and can scale from a small home server to a GPU workstation. Keep your containers updated, back up the volumes, and tune the model choice to your hardware for the best experience.

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

Debian Adoption at CERN Signals Strong Momentum for Enterprise Linux

By the end of this article readers will understand the implications of CERN’s migration of 2,200 control systems to Debian 13, the performance enhancements in Firefox 155, and recent developments across several Linux distributions that affect system administration and user experience. Debian 13 Deployment at CERN: Scale and Significance The European Organization for Nuclear Research (CERN) has announced the migration of 2,200 of its control systems to Debian 13. This move represents one of the largest coordinated deployments of a Debian release in a scientific research environment. Control systems at CERN are responsible for monitoring and managing critical hardware, from accelerator components to detector subsystems. Their reliability hinges on a stable operating system with long‑term support, predictable update cycles, and a robust package ecosystem. Debian’s reputation for stability and its extensive testing process make it a natural fit for such mission‑critical workloads. Debia...