【已解决】在dify中添加本地ollama模型时,提示An error occurred during credentials validation: HTTPConnectionPool
Docker部署Dify连接Ollama模型报错的解决方案:因容器内localhost指向自身,需将Ollama的基础URL从http://localhost:11434改为对应环境的地址。macOS/Windows用http://host.docker.internal:11434,Linux用http://172.17.0.1:11434,同网络容器则用服务名。修改后验证即可通过,可用curl
·
本地docker部署的dify,在dify中添加ollama模型时,提示
An error occurred during credentials validation: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/chat (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xffff8cb2cf50>: Failed to establish a new connection: [Errno 111] Connection refused'))
问了下kimi-k2,并参考改进,完美解决。
(PS:我的情况是“Docker Desktop on macOS”,对号入座即可)
方法如下:
Dify(跑在 Docker 容器里)把 localhost 理解成容器自己,而 Ollama 实际跑在宿主机的 11434 端口,所以连不上。
把「基础 URL」从 http://localhost:11434 改成下面任意一种即可:
| 运行方式 | 应填的基础 URL |
|---|---|
| Docker Desktop on macOS / Windows | http://host.docker.internal:11434 |
| Linux(Docker ≥ 20.10) | http://172.17.0.1:11434 |
如果 Ollama 也在 Docker 里,且两容器同属 dify_default 网络 |
http://ollama:11434 |
步骤
- 在 Dify → Settings → Model Provider → Ollama
- 把 Base URL 改成
http://host.docker.internal:11434 - 再次「Validate」即可通过。
附:如需验证
docker run --rm curlimages/curl \
http://host.docker.internal:11434/api/tags
能返回模型列表就说明 URL 正确。
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)