先决环境条件
- 操作系统 Ubuntu22.04
- 按照博客已经安装好了docker
- Ollama: 使用默认安装方法(官网https://github.com/ollama/ollama) curl -fsSL https://ollama.com/install.sh | sh 安装在本机
- OpenWebUI:使用默认docker安装方法(官网教程安装https://docs.openwebui.com/)
bash
docker run -d -p 3000:8080 \
-v open-webui:/app/backend/data \
--add-host=host.docker.internal:host-gateway \
-e OLLAMA_BASE_URL=http://host.docker.internal:11434 \
--name open-webui \
ghcr.io/open-webui/open-webui:main
遇到的问题
使用 http://127.0.0.1:11434/ 访问Ollama显示Ollama is running,说明Ollama正常。
Ollama中安装了模型,并且可以命令行形式使用。
使用http://localhost:3000/登录OpenWebUI后发现没有模型【这是端口号是3000不是8080,8080在我自己电脑上无法打开】
解决方法
- 看了网上的很多教程,没法解决。问题根本原因:openwebui docker内部无法访问宿主机的ollama服务,也就是
docker exec -it open-webui curl http://host.docker.internal:11434
返回的是curl: (7) Failed to connect to host.docker.internal port 11434 after 0 ms: Couldn't connect to server
- 运行编辑命令:
bash
# 1. 永久编辑ollama监听网址,如果只是OLLAMA_HOST=0.0.0.0 ollama serve这样重新启动ollama
# 你会发现可以openwebui docker内部确实可以访问 host.docker.internal port 11434了
# 但是,ollama list却显示不了你之前下载的模型了,必须通过systemctl
sudo systemctl edit ollama
# 2. 在nano编辑器里面输入,nano用法自行查找(注意坑:不能在最底下输入,必须在中间一段空地方输入,
# 否则不能有效保存,会被认为没有写,标志就是你写完还是会返回一句Editing ".../override.conf"
# canceled: temporary file is empty.):
[Service]
Environment="OLLAMA_HOST=0.0.0.0"
# 3. 查看 override 文件内容,可以看到我们刚刚写入的就成功了
cat /etc/systemd/system/ollama.service.d/override.conf
# 4. 重载并重启服务
sudo systemctl daemon-reload
sudo systemctl restart ollama
# 5. 最终验证:检查监听地址
ss -tuln | grep 11434
# 应该输出:tcp LISTEN 0 4096 *:11434 *:*
- 这时候在openwebui的"设置"-> "管理员面板"->"设置"->"外部连接"->"管理 Ollama API 连接",点击http://host.docker.internal:11434右边的
验证连接
就会发现能连上ollama了,点击保存。然后在上一步ollama list
可以看到下载的模型的基础上,刷新http://localhost:3000/界面,发现可以选择模型了!大功告成!
openwebui的功能还需进一步探索,可能没我们使用的各个公司的功能界面那样理想!