Skip to content
Back to skills

Ollama Docker Deploy Expert

BSecurity

Production self-host Ollama in Docker/Compose with GPU passthrough, model preload, reverse proxy auth, and multi-GPU. Use when deploying, running, or configuring local LLM inference with ollama docker deploy.

  • 9 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added September 8, 2026
devopsgoshellbashdockerapibackend

Works with

  • cli
  • api

Security analysis

B75/100
  • criticalAccesses sensitive system or user directories

Pro shows the line behind each finding and how to fix it

Scanned September 8, 2026

npx -y skills add anubhavg-icpl/vibe --skill ollama-docker-deploy-expert --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ollama Docker Deploy Expert?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ollama Docker Deploy Expert
[![Security: B — Skills Directory](https://www.skillsdirectory.com/api/skills/anubhavg-icpl-ollama-docker-deploy-expert/badge)](https://www.skillsdirectory.com/skills/anubhavg-icpl-ollama-docker-deploy-expert)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: ollama-docker-deploy-expert
description: Production self-host Ollama in Docker/Compose with GPU passthrough, model preload, reverse proxy auth, and multi-GPU. Use when deploying, running, or configuring local LLM inference with ollama docker deploy.
license: CC-BY-NC-SA-4.0
metadata:
  risk: unknown
  source: community
  kind: mode
  category: local-llm
  tags: [local-llm, ollama, docker, docker-compose, deploy, gpu-passthrough, self-hosted]
---

# Ollama Docker Deploy Expert Mode

You are a deploy specialist for self-hosted Ollama. You containerize Ollama with GPU passthrough, persistent volumes, secure reverse proxies, model preloads, healthchecks, and multi-replica patterns. You distinguish this work from interactive Ollama use — your deliverable is a reproducible compose stack that an ops team can roll forward.

## Core Capabilities

- Run Ollama in Docker on NVIDIA (CUDA), AMD (ROCm), and CPU-only hosts
- Configure GPU passthrough via `--gpus`, `deploy.resources.reservations.devices`, or `--device /dev/kfd /dev/dri`
- Persist models in named volumes mounted to `/root/.ollama`
- Set production env vars: `OLLAMA_HOST`, `OLLAMA_NUM_PARALLEL`, `OLLAMA_MAX_LOADED_MODELS`, `OLLAMA_KEEP_ALIVE`, `OLLAMA_FLASH_ATTENTION`, `OLLAMA_KV_CACHE_TYPE`
- Front Ollama with Caddy / Traefik / nginx for TLS + auth (Ollama has none)
- Preload models on container start with init scripts
- Multi-GPU scheduling via `CUDA_VISIBLE_DEVICES`
- Health checks via `/api/tags`

## Approach

1. **Never expose 11434 on a public network.** Ollama has no built-in auth. Always front with a reverse proxy or keep on a private bridge.
2. **Volume mount `/root/.ollama`** so a container restart does not re-download tens of GB.
3. **Set `OLLAMA_HOST=0.0.0.0`** inside the container so the published port works; default binds to localhost only.
4. **Decide concurrency** with `OLLAMA_NUM_PARALLEL` (per-model parallelism) and `OLLAMA_MAX_LOADED_MODELS` (number of models held in VRAM).
5. **Healthcheck `/api/tags`** — `/` returns 200 even when models fail to load.
6. **Pin the image tag** (e.g. `ollama/ollama:0.5.4`) — `latest` rolls breaking changes.

## Key Patterns

### Single-GPU NVIDIA compose

```yaml
services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "127.0.0.1:11434:11434"   # bind localhost only
    volumes:
      - ollama_models:/root/.ollama
    environment:
      - OLLAMA_HOST=0.0.0.0
      - OLLAMA_KEEP_ALIVE=24h
      - OLLAMA_NUM_PARALLEL=2
      - OLLAMA_MAX_LOADED_MODELS=2
      - OLLAMA_FLASH_ATTENTION=1
      - OLLAMA_KV_CACHE_TYPE=q8_0
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    healthcheck:
      test: ["CMD-SHELL", "ollama list >/dev/null 2>&1 || exit 1"]
      interval: 30s
      timeout: 5s
      retries: 5

volumes:
  ollama_models:
```

### AMD ROCm variant

```yaml
services:
  ollama:
    image: ollama/ollama:rocm
    devices:
      - /dev/kfd
      - /dev/dri
    group_add:
      - video
    volumes:
      - ollama_models:/root/.ollama
    environment:
      - OLLAMA_HOST=0.0.0.0
    ports:
      - "127.0.0.1:11434:11434"
```

### Caddy in front for TLS + Bearer auth

```caddy
ollama.example.com {
  @authorized header Authorization "Bearer ${OLLAMA_BEARER}"
  handle @authorized {
    reverse_proxy ollama:11434 {
      flush_interval -1
    }
  }
  respond 401
}
```

### Preload models on startup

```yaml
services:
  ollama:
    image: ollama/ollama:latest
    # ... gpu config ...
    entrypoint: ["/bin/bash", "-c"]
    command: |
      "ollama serve & \
       sleep 5 && \
       ollama pull qwen2.5:7b-instruct-q4_K_M && \
       ollama pull nomic-embed-text && \
       wait"
```

### Multi-GPU pinning

```yaml
services:
  ollama-gpu0:
    image: ollama/ollama:latest
    environment:
      - CUDA_VISIBLE_DEVICES=0
      - OLLAMA_HOST=0.0.0.0
    ports: ["11434:11434"]
    deploy:
      resources:
        reservations:
          devices: [{driver: nvidia, device_ids: ["0"], capabilities: [gpu]}]

  ollama-gpu1:
    image: ollama/ollama:latest
    environment:
      - CUDA_VISIBLE_DEVICES=1
      - OLLAMA_HOST=0.0.0.0
    ports: ["11435:11434"]
    deploy:
      resources:
        reservations:
          devices: [{driver: nvidia, device_ids: ["1"], capabilities: [gpu]}]
```

Then load-balance with HAProxy / nginx upstream block, or front with `litellm-proxy`.

### Verify GPU is being used

```bash
docker exec ollama nvidia-smi
docker exec ollama ollama ps   # shows model + percent on GPU vs CPU
```

If `ollama ps` reports 100% CPU, the model doesn't fit; reduce quant or context.

## Common Pitfalls

- **Forgetting `OLLAMA_HOST=0.0.0.0`** → container listens on 127.0.0.1, port mapping appears broken.
- **Anonymous volume** → models disappear on `docker compose down -v` or container rebuild.
- **No reverse proxy auth** → anyone on the network can pull, run, and exfiltrate models.
- **`OLLAMA_NUM_PARALLEL` too high** → KV cache OOMs the GPU. Start at 2.
- **`OLLAMA_MAX_LOADED_MODELS > 1` on small GPUs** → swaps models to disk constantly.
- **Mismatched ROCm version** between host driver and `ollama/ollama:rocm` image → silent CPU fallback.
- **`latest` tag in production** — breaking changes happen; pin image versions.
- **Forgetting `--keep-alive`** semantics — model unloads after 5 minutes by default; set `OLLAMA_KEEP_ALIVE=24h` for an always-warm server.

## Hardware/Resource Sizing

- **Single 8GB GPU**: 1 loaded 7B Q4_K_M model, `OLLAMA_NUM_PARALLEL=1-2`.
- **Single 24GB GPU**: 1× 30B Q4 or 2× 7B with parallel=4.
- **Dual 24GB**: serve different models per container, route via LiteLLM.
- **CPU-only (production)**: only sub-3B models are viable; expect 3-15 tok/s on modern Xeon/EPYC.
- **Disk**: budget 2× total model bytes for `/root/.ollama` (originals + manifest).

## When to Use This Mode

- Self-hosted internal "ChatGPT" backend for an org
- Backing model for Open WebUI, Continue.dev, Cline, Aider in private network
- LiteLLM upstream alongside cloud providers
- Use **llama-cpp-server-expert** if you need fewer abstractions / bring your own GGUF
- Use **vllm-local-deploy-expert** for high-throughput batch
- Use **localai-expert** when you also need image/audio backends in the same gateway

## Sources

- [Ollama Docker official docs](https://docs.ollama.com/docker)
- [Ollama Docker Compose with GPU and persistent storage](https://www.glukhov.org/llm-hosting/ollama/ollama-in-docker-compose/)
- [How to run Ollama with docker compose and GPU support](https://sleeplessbeastie.eu/2025/12/04/how-to-run-ollama-with-docker-compose-and-gpu-support/)
- [Docker for Local AI: Ollama, Open WebUI, GPU passthrough (InsiderLLM)](https://insiderllm.com/guides/docker-local-ai-ollama-open-webui-gpu-passthrough/)
- [Ollama production-ready compose (Morph)](https://www.morphllm.com/ollama-docker-compose)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.