Docker Compose for AI Apps: GPU, Ollama and a Vector Database in One Stack
Build a docker compose ai apps stack with Ollama, Open WebUI and a vector database: GPU setup, compose file, and the security steps that keep it private.
By Galactic News Editorial · Published 2026-11-18T19:47:18+00:00 · Updated 2026-11-18T19:47:18+00:00
Docker Compose for AI Apps: GPU, Ollama and a Vector Database in One Stack
A docker compose ai apps stack puts your whole local AI setup in one file: Ollama for inference, Open WebUI for chat, and a vector database for retrieval. One command starts it. The same file runs on your laptop, your home server, and a teammate's machine. This guide builds that stack with GPU support, persistent storage, and the security steps that keep it private.
What the stack looks like
Three services do the work. Ollama serves language models through an API on port 11434. Open WebUI gives you a chat interface in the browser, with knowledge bases for retrieval. The vector database stores document embeddings so the model can search your own files before answering. PostgreSQL with the pgvector extension covers both the app database and the vector store in one container. Qdrant is the alternative if you want a dedicated vector database with a REST API on port 6333 and gRPC on 6334.
All three tools are open source and free to self-host. Ollama and Open WebUI carry MIT licenses. pgvector is PostgreSQL-licensed. Nothing in the stack phones home, and no data leaves your machine unless you choose to send it somewhere.
Docker compose ai apps: the GPU question first
Sort out the GPU before writing the compose file. On Linux with an NVIDIA card, install the NVIDIA Container Toolkit, then configure Docker to use the NVIDIA runtime. Ollama's own Docker documentation lists exactly this path, with install steps for apt and yum, plus AMD support through the rocm image tag and Vulkan support bundled in the image. GPU acceleration in Docker is not available on macOS, because Docker Desktop there has no GPU passthrough. On a Mac, run Ollama natively and keep only Open WebUI in Docker.
Without a GPU, the stack still works. Ollama falls back to CPU inference automatically. Expect slower responses, roughly 10 to 30 seconds per reply for a small model, against 1 to 3 seconds on a GPU. For a first build, CPU is fine. Add the GPU block later when you know the stack works.
Step 1: write the compose file
Create a project folder and a compose file inside it. The file below runs Ollama with GPU access, Open WebUI, and Qdrant as the vector database. Swap Qdrant for PostgreSQL with pgvector if you prefer one database for both jobs.
services:
ollama:
image: ollama/ollama:latest
container_name: ollama
restart: unless-stopped
ports:
- "127.0.0.1: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:main
container_name: open-webui
restart: unless-stopped
ports:
- "127.0.0.1:3000:8080"
environment:
- OLLAMA_BASE_URL=http://ollama:11434
volumes:
- open_webui_data:/app/backend/data
depends_on:
- ollama
qdrant:
image: qdrant/qdrant
container_name: qdrant
restart: unless-stopped
ports:
- "127.0.0.1:6333:6333"
- "127.0.0.1:6334:6334"
volumes:
- qdrant_storage:/qdrant/storage
environment:
QDRANT__SERVICE__API_KEY: ${QDRANT_API_KEY}
volumes:
ollama_data:
open_webui_data:
qdrant_storage:
Three details matter here. First, every port binds to 127.0.0.1, so the services answer only on your own machine. Second, each service gets a named volume, so models, chats and vectors survive a restart. Third, Qdrant gets an API key from an environment variable, because it checks no credentials by default.
Step 2: start the stack and pull a model
- Set the API key. Create a
.envfile in the project folder with a long random value forQDRANT_API_KEY. - Start the services. Run
docker compose up -dfrom the project folder. - Check the logs. Run
docker compose logs -f ollamaand confirm the server started without GPU errors. - Pull a model. Run
docker exec ollama ollama pull llama3.1:8bfor a general model, or a smaller one if your machine is tight on memory. - Open the interface. Visit
http://localhost:3000, create the first admin account, and pick the model you pulled. - Test retrieval. Upload a document to a knowledge base in Open WebUI and ask a question about it. The answer should reference your document.
Step 3: wire the vector database to retrieval
Open WebUI ships with its own vector store, so a separate database is optional for simple use. It earns its place when you need persistent retrieval across restarts, shared collections, or a second app reading the same vectors. With Qdrant, create a collection with the embedding size your model produces, then upsert points with the document text as payload. Point Open WebUI or your app at http://qdrant:6333 inside the compose network.
With the pgvector route instead, run PostgreSQL 17 with the pgvector image and give Open WebUI the database URL. The same instance holds the app data and the embeddings, which means one database to back up. Open WebUI then stores knowledge base vectors in pgvector rather than its default store.
Hardware: what to expect
| Setup | RAM | GPU | What runs |
|---|---|---|---|
| Minimum, CPU only | 16 GB | None | Small 7B models at a few tokens per second |
| Comfortable | 16 GB | RTX 3060 12GB | 7B models at usable chat speed |
| Recommended | 32 GB | RTX 4070 12GB | 14B models plus embeddings on GPU |
| Heavy retrieval | 64 GB | RTX 4090 24GB | Large models and big document sets |
The embedding model runs beside the inference model. On an 8GB card they compete for memory, and the inference model may partly offload to CPU. A 12GB card keeps both on the GPU. Watch memory with nvidia-smi while the stack runs.
Security and upkeep checklist
- Bind every port to 127.0.0.1 unless a reverse proxy with authentication sits in front.
- Set a Qdrant API key before the first start, and keep it in a
.envfile, not in the compose file. - Pin image tags instead of using
latestonce the stack works, so an update cannot break it silently. - Back up the named volumes. That is where models, chats and vectors live.
- Update the host NVIDIA driver before blaming the container when GPU detection fails.
- Test with
docker run --gpus all ubuntu nvidia-smi. If that fails, Ollama cannot see the GPU either.
Bottom line
One compose file, three services, and your data never leaves the machine. Start with Ollama and Open WebUI on CPU if you have no GPU. Add the GPU block and a vector database once the basic stack answers questions. Keep ports on localhost, set the API key, and back up the volumes. That is the whole stack, and it is enough to build real retrieval apps on.