发布于 2026-01-06 3 阅读
0

从群体到宿主:通过 Docker 化的 Ollama 暴露 LLaMA

从群体到宿主:通过 Docker 化的 Ollama 暴露 LLaMA

使用Ollama在 Docker 容器内轻松部署 LLaMA 模型,并通过端口将其暴露给外部访问11434


🧰 先决条件

  • Docker 已安装
  • LLaMA模型所需的内存和磁盘空间足够
  • (可选)本地 Ollama CLI 用于在容器外部进行测试

🛠️ 第一步:创建 Dockerfile

FROM ollama/ollama:latest

# Pull the LLaMA model inside the container
RUN ollama pull llama

# Expose default Ollama port
EXPOSE 11434

# Start Ollama server on container startup
CMD ["ollama", "serve", "--port", "11434"]
Enter fullscreen mode Exit fullscreen mode

将其另存为Dockerfile


🏗️ 第二步:构建 Docker 镜像

docker build -t ollama-llama .
Enter fullscreen mode Exit fullscreen mode

🚀 第三步:运行容器

docker run -d -p 11434:11434 --name ollama-llama-container ollama-llama
Enter fullscreen mode Exit fullscreen mode

这将把 Ollama LLaMA 服务器暴露在外http://localhost:11434


💬 第四步:与模型互动

使用 HTTP 发送请求或使用ollamaCLI:

curl http://localhost:11434
Enter fullscreen mode Exit fullscreen mode

ollama run llama如果已安装 CLI 并指向此容器,您也可以使用它。


📝 备注

  • 根据需要替换llamallama2llama3或特定型号名称。
  • 如果需要持久化模型缓存,请使用卷挂载。
  • 使用以下命令监控容器日志:
docker logs -f ollama-llama-container
Enter fullscreen mode Exit fullscreen mode

📚 资源

文章来源:https://dev.to/moni121189/from-herd-to-host-exusing-llama-via-dockerized-ollama-3hhc