当尝试从 docker compose 设置中的另一个(节点)服务访问 ollama 容器时,出现以下错误:
ResponseError: model 'llama3' not found, try pulling it first
。我希望容器的设置是自动的,并且不想手动连接到容器并手动拉取模型。
有没有办法在创建 ollama docker 容器时自动加载我选择的模型?
这是我的 docker-compose.yml 的相关部分
ollama:
image: ollama/ollama:latest
ports:
- 11434:11434
volumes:
- ./ollama/ollama:/root/.ollama
container_name: ollama
pull_policy: always
tty: true
restart: always
启动容器时使用自定义入口点脚本下载模型。该模型将保留在卷安装中,因此这将在后续启动中快速进行。
version: '3.7'
services:
ollama:
image: ollama/ollama:latest
ports:
- 11434:11434
volumes:
- ./ollama/ollama:/root/.ollama
- ./entrypoint.sh:/entrypoint.sh
container_name: ollama
pull_policy: always
tty: true
restart: always
entrypoint: ["/usr/bin/bash", "/entrypoint.sh"]
主要变化:
entrypoint
。entrypoint.sh
的卷安装。这就是
entrypoint.sh
的内容:
#!/bin/bash
# Start Ollama in the background.
/bin/ollama serve &
# Record Process ID.
pid=$!
# Pause for Ollama to start.
sleep 5
echo "🔴 Retrieve LLAMA3 model..."
ollama pull llama3
echo "🟢 Done!"
# Wait for Ollama process to finish.
wait $pid