Docker Compose configuration for running LocalAI with NVIDIA GPU support. Includes a single-machine dev setup and a distributed multi-node setup.
- Docker with Compose v2
- NVIDIA GPU with Container Device Interface (CDI) configured
- The
local-aiDocker image (locally built from the LocalAI repo)
Single machine with LocalAI + Caddy (HTTPS for WebRTC):
# Set up Caddy config
cp Caddyfile.example Caddyfile.local
# Edit Caddyfile.local - replace YOUR_HOSTNAME with your machine's hostname
docker compose -f docker-compose.dev.yaml upLocalAI is available at http://localhost:8081 (HTTP) and https://YOUR_HOSTNAME:8443 (HTTPS via Caddy).
Distributed mode splits the frontend API server and GPU workers, connected via NATS.
cp Caddyfile.example Caddyfile.local
# Edit Caddyfile.local
docker compose -f docker-compose.distributed.yaml --profile local upThis starts PostgreSQL, NATS, LocalAI frontend, Caddy, and a local GPU worker.
cp .env.example .env
# Edit .env - set FRONTEND_HOST to the frontend machine's hostname
docker compose -f docker-compose.distributed.yaml --profile remote up| File | Purpose |
|---|---|
Caddyfile.local |
Caddy reverse proxy config (copy from Caddyfile.example) |
.env |
Environment variables for distributed mode (copy from .env.example) |
volumes/configuration/runtime_settings.json |
LocalAI runtime settings (threads, tracing, galleries, agent pool, etc.) - created via the LocalAI UI or manually |
The volumes/ directory is mounted into containers. Directory structure is preserved in git via .gitkeep files; contents are gitignored.
| Directory | Container mount | Purpose |
|---|---|---|
volumes/models/ |
/models |
Model weights (GGUF), configs, gallery definitions |
volumes/backends/ |
/backends |
CUDA backend libraries |
volumes/content/ |
/tmp/generated/content |
Generated audio, images, and videos |
volumes/data/ |
/data |
Runtime data, collections, assets |
volumes/configuration/ |
/configuration |
Runtime settings JSON |
volumes/images/ |
- | Container images |
volumes/postgres/ |
/var/lib/postgresql |
PostgreSQL data (distributed mode) |
volumes/worker-models/ |
/models |
Model weights for remote workers |
- Docker image: Both compose files use
image: local-ai, a locally built image. Build it from the LocalAI source or change it to an official image likelocalai/localai:latest-gpu-nvidia-cuda-12. - User/group: Containers run as
user: "1000:100"(typical first Linux user,usersgroup). Adjust if your UID/GID differs. - GPU driver: Uses CDI (
driver: cdi). If your NVIDIA Container Toolkit doesn't support CDI, switch to the olderruntime: nvidiaapproach.