Files
nexus/wiki/concepts/Docker-LLM-Deployment.md

84 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Docker LLM Deployment"
type: concept
tags: []
last_updated: 2026-04-23
---
# Docker LLM Deployment
## Definition
通过 Docker 容器化方式部署本地大语言模型运行时LLM及其周边工具Web 界面、RAG 引擎等),实现环境隔离、可移植性和便捷管理的部署模式。
## Core Patterns
### Pattern 1: Ollama 独立容器
```bash
# CPU 模式
docker run -d -p 11434:11434 \
-v /data/ollama:/root/.ollama \
--name ollama ollama/ollama
# GPU 模式(需 nvidia-container-toolkit
docker run --gpus=all -d -p 11434:11434 \
-v /data/ollama:/root/.ollama \
--name ollama ollama/ollama
```
### Pattern 2: Ollama + Open WebUI 联合部署
```yaml
services:
ollama:
image: ollama/ollama
volumes:
- /data/ollama:/root/.ollama
# GPU 模式
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
open-webui:
image: ghcr.io/open-webui/open-webui:main
environment:
- OLLAMA_API_BASE_URL=http://ollama:11434/api
ports:
- 8080:8080
depends_on:
- ollama
```
## Key Advantages
| 优势 | 说明 |
|------|------|
| 环境隔离 | 避免依赖冲突,不污染宿主机 |
| GPU 直通 | `--gpus=all` 直接利用宿主 GPU |
| 便捷迁移 | 镜像导出/导入实现跨机器部署 |
| 统一管理 | `docker compose up/down` 控制启停 |
| 卷挂载 | 模型数据持久化到宿主机目录 |
## Key Environment Variables
| 变量 | 说明 | 示例 |
|------|------|------|
| OLLAMA_MODELS | 模型存储路径 | `/data/ollama/models` |
| OLLAMA_HOST | API 绑定地址 | `0.0.0.0:11434` |
| OLLAMA_ORIGINS | 允许的跨域来源 | `*` |
| HF_ENDPOINT | HuggingFace 镜像 | `https://hf-mirror.com` |
## China Environment Best Practices
- 设置 `HF_ENDPOINT=https://hf-mirror.com` 加速镜像拉取
- 预先拉取镜像:`docker pull ollama/ollama ghcr.io/open-webui/open-webui:main`
- 通过 volume 挂载宿主机模型目录避免重复下载
- 模型目录规划:`/data/ollama/models` 集中管理所有 GGUF 文件
## Related Concepts
- [[Local LLM Deployment]]Docker 部署是本地 LLM 的一种实现方式
- [[Ollama]]Ollama Docker 镜像是核心运行时
- [[Open WebUI]]Ollama 的 Web 界面伴侣
## Sources
- [[详细-离线部署大模型-ollama-deepseek-open-webui安装使用方法及常见问题解决-1]]