使用 Docker Compose 安装 Ollama 及模型

docker-compose.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
networks:
ollama:
external: true

services:
ollama:
image: ollama/ollama:0.4.1
container_name: ollama
restart: always
networks:
- ollama
deploy:
resources:
reservations:
# noinspection ComposeUnknownValues
devices:
- driver: nvidia
capabilities: [ gpu ]
environment:
- OLLAMA_KEEP_ALIVE=24h
volumes:
- "${COMPOSE_DATA_DIR:-/data}/ollama/ollama:/root/.ollama"
ports:
- "11434:11434"

ollama-webui:
image: ghcr.io/open-webui/open-webui:0.3.35
container_name: ollama-webui
restart: always
networks:
- ollama
environment:
- OLLAMA_BASE_URL=http://ollama:11434
- ENV=dev
- WEBUI_AUTH=False
- WHISPER_MODEL_AUTO_UPDATE=False
- RAG_EMBEDDING_MODEL_AUTO_UPDATE=False
- RAG_RERANKING_MODEL_AUTO_UPDATE=False
volumes:
- "${COMPOSE_DATA_DIR:-/data}/ollama/webui:/app/backend/data"
ports:
- "8080:8080"

拉取模型

  • https://ollama.com/library
  • https://ollama.com/library/qwen2.5
1
docker exec -it ollama bash
1
2
3
ollama list
ollama pull qwen2.5
ollama list

使用模型

打开 http://${IP}:8080 访问 webui,左上角选择模型 qwen2.5

webui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 565.57.01 Driver Version: 565.57.01 CUDA Version: 12.7 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 Tesla T4 Off | 00000000:00:10.0 Off | 0 |
| N/A 33C P0 25W / 70W | 5255MiB / 15360MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
| 1 Tesla T4 Off | 00000000:00:11.0 Off | 0 |
| N/A 24C P8 9W / 70W | 3MiB / 15360MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| 0 N/A N/A 326540 C ...unners/cuda_v12/ollama_llama_server 5252MiB |
+-----------------------------------------------------------------------------------------+