Ollama in Docker betreiben
Was dieser Artikel über Ollama in Docker behandelt
- Warum Ollama in Docker laufen lassen.
- Einfache Docker-Installation.
- GPU-Passthrough für NVIDIA und AMD.
- Docker-Compose-Setup.
- Tipps für Persistenz und Updates.
Einleitung: Ollama in Docker betreiben
Ollama wird oft direkt auf dem Host installiert, lässt sich aber auch sehr gut in einem Docker-Container betreiben. Das vereinfacht Updates, Isolation und Reproduzierbarkeit. Mit GPU-Passthrough kann Docker Ollama auf der Grafikkarte laufen lassen, genau wie eine native Installation. Für Homelabs und Server ist Docker eine saubere Möglichkeit, Ollama zu verwalten.
Dieser Artikel zeigt, wie Ollama in Docker installiert und konfiguriert wird.
Wichtige Begriffe
- Container: Isolierte Laufzeitumgebung.
- Volume: Persistenter Speicher.
- GPU-Passthrough: GPU im Container verfügbar machen.
- Compose: Mehrere Container deklarativ definieren.
- NVIDIA Container Toolkit: Werkzeuge für GPU in Docker.
- runtime: Container-Runtime für GPU.
- .ollama: Ollama-Datenverzeichnis.
- Port-Mapping: Weiterleitung eines Host-Ports an Container.
Einfaches Docker-Kommando
docker run -d \
-v ollama:/root/.ollama \
-p 11434:11434 \
--name ollama \
ollama/ollama
Mit NVIDIA GPU
Voraussetzung: NVIDIA Container Toolkit installiert.
docker run -d \
--gpus all \
-v ollama:/root/.ollama \
-p 11434:11434 \
--name ollama \
ollama/ollama
Mit AMD GPU
docker run -d \
--device /dev/kfd \
--device /dev/dri \
-v ollama:/root/.ollama \
-p 11434:11434 \
--name ollama \
ollama/ollama:rocm
Docker Compose
services:
ollama:
image: ollama/ollama:latest
container_name: ollama
ports:
- "11434:11434"
volumes:
- ollama-data:/root/.ollama
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
volumes:
ollama-data:
NVIDIA-Compose für GPU
services:
ollama:
image: ollama/ollama:latest
container_name: ollama
ports:
- "11434:11434"
volumes:
- ollama-data:/root/.ollama
runtime: nvidia
environment:
- NVIDIA_VISIBLE_DEVICES=all
volumes:
ollama-data:
AMD-Compose
services:
ollama:
image: ollama/ollama:rocm
container_name: ollama
ports:
- "11434:11434"
volumes:
- ollama-data:/root/.ollama
devices:
- /dev/kfd
- /dev/dri
volumes:
ollama-data:
Modell herunterladen
docker exec -it ollama ollama pull llama3.1
Testen
curl http://localhost:11434/api/tags
Updates
docker pull ollama/ollama:latest
docker stop ollama
docker rm ollama
docker compose up -d
Oder einfach im Compose:
docker compose pull
docker compose up -d
Daten sichern
Das Volume ollama-data enthält Modelle und Konfiguration:
docker run --rm -v ollama-data:/data -v $(pwd):/backup alpine \
tar -czf /backup/ollama-backup.tar.gz -C /data .
Vorteile
- Einfache Updates.
- Reproduzierbare Installation.
- Isolation vom Host.
- Leichte Integration in Compose-Umgebungen.
- Gute Skalierbarkeit auf Servern.
Limitierungen
- GPU-Passthrough erfordert korrekte Treiber und Toolkit.
- USB/Geräte nicht immer einfach.
- Rechte im Volume beachten.
Tipps
- Volume persistent halten.
- Keine Modelle im Container-Layer speichern.
- Container nur neu starten, nicht löschen, wenn möglich.
- Tags verwenden statt
latestin Produktion. - Logs regelmässig prüfen.
- GPU-Treiber vorher installieren.
Typische Stolpersteine
- GPU nicht erkannt: NVIDIA Container Toolkit oder ROCm fehlt.
- Keine GPU-Sichtbarkeit:
deploy.resourcesstattruntime: nvidiabei neuer Docker Compose-Version. - Volume gelöscht: Modelle weg.
- Rechteprobleme: Container läuft als root.
- Neueste Images:
latestkann unerwartete Änderungen bringen.
Weiterführende Links und Infos
- BotServ.de Ollama Remote-Zugriff
- BotServ.de Docker GPU-Passthrough
- BotServ.de Docker Compose
- BotServ.de Ollama GPU-Unterstützung
FAQ: Ollama in Docker
Brauche ich eine GPU? Nein, aber ohne GPU läuft Ollama langsamer auf CPU.
Wie starte ich Ollama im Docker?
Mit ollama serve, das Image macht das automatisch.
Wo werden Modelle gespeichert?
Im Volume /root/.ollama.
Kann ich mehrere Ollama-Container laufen lassen? Nur auf verschiedenen Ports und mit getrennten Daten.
Welches Image für AMD?
ollama/ollama:rocm.
Quellen und weiterführende Literatur
- Ollama Docker Image: https://ollama.com/blog/ollama-is-now-available-as-an-official-docker-image
- NVIDIA Container Toolkit: https://github.com/NVIDIA/nvidia-container-toolkit
- Docker GPU: https://docs.docker.com/compose/gpu-support/
Zusammenfassung: Ollama in Docker betreiben
Ollama in Docker zu betreiben ist eine saubere, reproduzierbare Möglichkeit, Modelle lokal oder auf einem Server zu nutzen. Mit GPU-Passthrough und einem persistenten Volume funktioniert es nahezu wie eine native Installation. Updates, Backups und Integration in grössere Compose-Setups sind einfacher. Wer das NVIDIA Container Toolkit oder ROCm korrekt einrichtet, bekommt GPU-Beschleunigung im Container.


