Deploy Ollama and Open WebUI with NVIDIA GPU on Ubuntu using Docker Compose (2025 Guide)

Running a private, GPU-accelerated AI assistant is now easier than ever. In this step-by-step guide, you will deploy Ollama (for running LLMs locally) and Open WebUI (a clean browser interface) on Ubuntu 22.04/24.04 using Docker Compose with NVIDIA GPU support. This setup is fast, reproducible, and ideal for teams or power users who want a self-hosted ChatGPT-like experience with full control.

Prerequisites

Before you begin, you will need:

- An Ubuntu 22.04 or 24.04 server or workstation.
- An NVIDIA GPU with recent drivers (e.g., RTX 20/30/40 series or A-series).
- Docker Engine, Docker Compose (v2), and the NVIDIA Container Toolkit.
- At least 20 GB free disk space and adequate RAM/VRAM (8–24 GB VRAM recommended for larger models).

Step 1: Install Docker Engine and Compose

Install Docker using the official repository for reliability and updates:

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

Step 2: Install NVIDIA Container Toolkit

The NVIDIA Container Toolkit enables GPU access from containers. Install and verify it as follows:

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

If nvidia-smi shows your GPU and driver information, you are ready.

Step 3: Create a Docker Compose file

We will run two services: ollama (the model server) and open-webui (the frontend). The configuration below binds ports to localhost for security, so the services are not accessible from the public internet by default.

mkdir -p ~/ollama-openwebui && cd ~/ollama-openwebui
cat > docker-compose.yml << 'EOF'
services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "127.0.0.1:11434:11434"
    volumes:
      - ollama:/root/.ollama
    environment:
      - OLLAMA_KEEP_ALIVE=8h
    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_BASE_URL=http://ollama:11434
    ports:
      - "127.0.0.1:3000:8080"
    volumes:
      - open-webui:/app/backend/data

volumes:
  ollama:
  open-webui:
EOF

If you do not have an NVIDIA GPU or want CPU-only, remove the deploy.resources block in the ollama service and optionally set OLLAMA_NUM_THREADS in the environment.

Step 4: Start the stack

Pull the images and launch the services in the background:

docker compose pull
docker compose up -d
docker compose ps

Open WebUI will be available at http://127.0.0.1:3000 on the host. The first load may take a moment.

Step 5: Pull a model and run your first chat

Ollama manages models. Use the following commands to pull a model (for example, llama3.1) and verify it works:

docker exec -it ollama ollama list
docker exec -it ollama ollama pull llama3.1
docker exec -it ollama ollama run llama3.1 "Write a haiku about GPUs."

Now visit Open WebUI on http://127.0.0.1:3000. In Settings > Models, you should see the pulled model. Start chatting. If you need a smaller or faster model, try llama3.1:8b, mistral, or qwen2. For larger models, ensure your GPU memory is sufficient.

Optional: Access from your LAN or the Internet

- For LAN access, change the port bindings in docker-compose.yml from 127.0.0.1:3000:8080 to 0.0.0.0:3000:8080 and repeat for port 11434 if needed, then run docker compose up -d.
- For internet exposure, use a reverse proxy (Nginx, Caddy, Traefik) with HTTPS (Let’s Encrypt) and keep 11434 internal. Never expose Ollama’s API publicly without authentication.

Resource tuning and tips

- Set OLLAMA_KEEP_ALIVE to control model unload time (e.g., 8h).
- For CPU installs, set OLLAMA_NUM_THREADS=$(nproc).
- Use quantized models (e.g., llama3.1:8b-instruct-q4_K_M) if VRAM is limited.
- Persist data: models live in the ollama volume; Open WebUI settings and chats live in the open-webui volume.
- Backups: snapshot /var/lib/docker/volumes/<name>/_data or use docker run --rm -v volume:/data -v $(pwd):/backup alpine tar czf /backup/volume.tgz -C / data.

Troubleshooting

- GPU not detected: Ensure drivers are installed and nvidia-smi works on the host. Re-run sudo nvidia-ctk runtime configure --runtime=docker, restart Docker, and verify Compose GPU reservations are present.
- Out of memory (VRAM): Choose a smaller/quantized model. Watch container logs: docker logs -f ollama.
- Slow performance on CPU: Reduce context window, use smaller models, and set threads to the number of CPU cores.
- Port conflicts: Adjust the host ports in the Compose file (e.g., 127.0.0.1:13000:8080).

Updating and maintenance

Keep images fresh and stable with a simple routine:

cd ~/ollama-openwebui
docker compose pull
docker compose up -d
docker image prune -f

Model files are cached in the ollama volume. Removing the container will not delete models unless you remove the volume explicitly.

Conclusion

You have deployed a modern, private AI chat stack powered by Ollama and Open WebUI with GPU acceleration on Ubuntu. With Docker Compose, the setup is reproducible and easy to maintain. You can now experiment with state-of-the-art open models, keep data on your hardware, and scale up or down by swapping models or hardware. If you want advanced features like multi-user support, role-based access, or external tools, explore Open WebUI’s settings and plug-ins—and enjoy your self-hosted AI assistant.

Deploy Ollama and Open WebUI on Ubuntu 24.04 with NVIDIA GPU, Docker Compose, and Traefik TLS

Overview

This tutorial shows how to deploy a secure, GPU-accelerated local AI stack on Ubuntu 24.04 using Docker Compose. We will run Ollama for model inference and Open WebUI as a sleek web interface, fronted by Traefik for reverse proxy, HTTPS (Let’s Encrypt), and basic authentication. You will get a production-ready setup that supports NVIDIA GPUs and is protected with TLS and a login prompt.

Prerequisites

- Ubuntu 24.04 LTS with a modern NVIDIA GPU (e.g., RTX series).
- A public DNS record (e.g., ai.example.com) pointing to your server’s IP.
- Ports 80 and 443 open in the firewall or cloud security group.
- A sudo-enabled user on the server.
- Docker and the Docker Compose plugin installed (Ubuntu’s docker.io + docker-compose-plugin or Docker’s official packages).
- An email address for Let’s Encrypt certificates.

1) Install NVIDIA Driver and Container Toolkit

First, make sure the proprietary NVIDIA driver is installed and working. On Ubuntu 24.04, the recommended driver is usually offered by “Additional Drivers” or via apt:

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

After reboot, confirm the driver and GPU are detected:

nvidia-smi

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

2) Prepare Docker Network and Directory

Create a dedicated network and a working directory for the stack:

docker network create ai_net || true
mkdir -p ~/ai-stack/{letsencrypt,ollama}

3) Create HTTP Basic Auth for Open WebUI

We will protect the web UI with Traefik’s basic auth. Generate a bcrypt hash with htpasswd. Note: when placing the hash in docker-compose labels, escape each $ as $$.

sudo apt install -y apache2-utils
htpasswd -nbB aiadmin 'StrongP@ssw0rd!'

You will get output like aiadmin:$2y$05$abc.... Copy it for the next step and remember to replace each $ with $$ in the compose file.

4) Write docker-compose.yml

Create ~/ai-stack/docker-compose.yml with the following content. Replace ai.example.com and [email protected] with your values. Also paste your basic auth user:hash in the indicated line, with dollars escaped as $$.

version: '3.8'

services:
traefik:
image: traefik:v3.0
container_name: traefik
command:
- --api.dashboard=false
- --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- [email protected]
- --certificatesresolvers.le.acme.storage=/letsencrypt/acme.json
- --certificatesresolvers.le.acme.httpchallenge=true
- --certificatesresolvers.le.acme.httpchallenge.entrypoint=web
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./letsencrypt:/letsencrypt
networks:
- ai_net

ollama:
image: ollama/ollama:latest
container_name: ollama
environment:
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=compute,utility
volumes:
- ./ollama:/root/.ollama
networks:
- ai_net
deploy:
resources:
reservations:
devices:
- capabilities: [gpu]

openwebui:
image: ghcr.io/open-webui/open-webui:latest
container_name: openwebui
environment:
- OLLAMA_BASE_URL=http://ollama:11434
depends_on:
- ollama
networks:
- ai_net
labels:
- traefik.enable=true
- traefik.http.routers.openwebui.rule=Host(`ai.example.com`)
- traefik.http.routers.openwebui.entrypoints=websecure
- traefik.http.routers.openwebui.tls.certresolver=le
- traefik.http.services.openwebui.loadbalancer.server.port=8080
- traefik.http.routers.openwebui.middlewares=openwebui-auth
- traefik.http.middlewares.openwebui-auth.basicauth.users=aiadmin:$$2y$$05$$REPLACE_WITH_YOUR_HASH

networks:
ai_net:
external: true

Notes: The deploy.resources.devices section in Compose is ignored outside Swarm, but many users report it still helps Compose detect GPUs with the NVIDIA Container Toolkit. If your GPU is not picked up, add runtime: nvidia under the ollama service or map NVIDIA devices explicitly.

5) Launch the Stack

Start everything in the background:

cd ~/ai-stack
docker compose up -d

Confirm that Traefik, Ollama, and Open WebUI are running:

docker ps

Wait 10–30 seconds for Let’s Encrypt to issue the certificate. Then visit https://ai.example.com. You should see a basic auth prompt. Enter your credentials and access Open WebUI.

6) Pull a Model and Test

From the Open WebUI interface, add a model like llama3:8b or phi3:mini. Alternatively, pull via CLI:

docker exec -it ollama ollama pull llama3:8b
docker exec -it ollama ollama run llama3:8b "Explain containers in one paragraph."

Open WebUI will connect to Ollama at http://ollama:11434 and use your GPU to accelerate inference if it is available.

Troubleshooting

- If nvidia-smi fails on the host, fix the driver first. The container cannot use a GPU your OS cannot see.
- If Open WebUI shows a connection error, check logs: docker logs openwebui -f and docker logs ollama -f.
- If certificates are not issued, ensure ports 80/443 are open and DNS is correct. Review docker logs traefik -f.
- If basic auth is not accepted, verify you escaped $ characters as $$ in the label.
- To keep models between upgrades, never delete the ./ollama folder.

Optional Hardening

- Restrict access by IP allowlists with Traefik middlewares in addition to basic auth.
- Set LOG_LEVEL=ERROR in Traefik if you want quieter logs.
- If exposing the Ollama API externally, add its own router, TLS, and auth. By default in this guide, the Ollama API is internal only.

Maintenance

Update images periodically and redeploy:

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

To stop the stack:

docker compose down

You now have a secure, GPU-ready, self-hosted AI chat environment with automatic HTTPS on Ubuntu 24.04, powered by Docker, Traefik, Ollama, and Open WebUI.

Install Ollama and Open WebUI on Ubuntu 24.04 with Docker (GPU or CPU) — Step-by-Step

Overview

This guide shows you how to self-host a private ChatGPT-like interface on Ubuntu 24.04 using Ollama and Open WebUI. You will deploy both apps with Docker, enable optional NVIDIA GPU acceleration, and connect them securely. The result is a fast, local AI stack that can run popular open-source models like Llama 3 and Mistral without sending your data to the cloud.

Prerequisites

- A server or VM running Ubuntu 24.04 LTS with a sudo user
- Stable internet connection and at least 10 GB free disk space (more is better for models)
- Optional: NVIDIA GPU (Turing or newer recommended), proprietary drivers installed, and CUDA-capable

1) Install Docker and prepare the host

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

sudo apt update && sudo apt upgrade -y
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 support for Docker

If you have an NVIDIA GPU, install the proprietary driver and the NVIDIA Container Toolkit to let containers access the GPU.

Install driver (if not already):
sudo ubuntu-drivers install
sudo reboot

Verify after reboot:
nvidia-smi should show your GPU.

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

3) Create persistent volumes

Create directories for model files and the Open WebUI database so your data survives container updates:

mkdir -p ~/ollama-data ~/openwebui-data

4) Run the Ollama container (CPU or GPU)

Ollama serves models over an HTTP API on port 11434. Use one of the following commands:

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

GPU-enabled:
docker run -d --name ollama --gpus all --restart unless-stopped -p 11434:11434 -v ~/ollama-data:/root/.ollama ollama/ollama:latest

Pull a model to test the setup (choose one):

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

5) Deploy Open WebUI and connect it to Ollama

Open WebUI is a fast, modern interface that talks to Ollama via API. Put them on the same Docker network so the UI can resolve the Ollama container by name.

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

Open your browser and navigate to http://SERVER_IP:3000. Create the first admin user when prompted. In Settings, choose the default model you pulled earlier (for example, llama3.1:8b), then start chatting.

6) Optional: HTTPS with a free certificate (Caddy)

If the server is reachable from the internet with a DNS name, you can place Caddy in front to get automatic HTTPS via Let’s Encrypt.

Create a simple Caddyfile:
mkdir -p ~/caddy && nano ~/caddy/Caddyfile

Example Caddyfile (replace ai.example.com with your domain):

ai.example.com {
  reverse_proxy 127.0.0.1:3000
}

Run Caddy:

docker run -d --name caddy --restart unless-stopped -p 80:80 -p 443:443 -v ~/caddy/Caddyfile:/etc/caddy/Caddyfile -v caddy_data:/data -v caddy_config:/config caddy:latest

7) Updating, backups, and management

Update containers:
docker pull ollama/ollama:latest
docker pull ghcr.io/open-webui/open-webui:latest
docker stop openwebui ollama && docker rm openwebui ollama
# Re-run the same docker run commands used earlier

Logs and health:
docker logs -f ollama
docker logs -f openwebui

Backups: the important data lives in ~/ollama-data (models, manifests) and ~/openwebui-data (users, settings, chats). Back up these folders with your usual tool (rsync, restic, borg, etc.).

Troubleshooting

- If GPU is not used: verify with docker run --rm --gpus all nvidia/cuda:12.4.1-base-ubuntu22.04 nvidia-smi. If it fails, confirm the driver, toolkit, and that Docker was restarted after nvidia-ctk configuration.
- If Open WebUI cannot see models: ensure both containers share the same network (ai) and that OLLAMA_BASE_URL=http://ollama:11434 is set.
- If port conflicts occur: change the host ports (for example, -p 3001:8080) or stop the service using the port.

What you built

You now have a secure, private, and fast AI stack on Ubuntu 24.04: Ollama handles model execution with optional GPU acceleration, and Open WebUI provides a clean, multi-user chat interface. This setup is easy to maintain with Docker, simple to back up, and flexible enough to add new models or scale to stronger GPUs later.

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