Windows 中使用 docker 部署 AnythingLLM
- 需求:为了满足多人共享本地知识库,同时便于统一管理知识库,所以需要一个可以多人共享的客户端,最好是 web 应用。
- 准备:查阅资料发现 AnythingLLM 可以满足要求,但是需要 Linux 系统的 docker 部署,由于服务器和本地电脑都是 windows 系统,所以尝试在 WSL 中部署。
- 结论:通过实验证明 Windows server2019 无法部署,查阅资料显示,Windows Server2019 只支持 WSL1,无法支持 WSL2,而 WSL1 中的 Linux 内核是不完整的,不能支持全部功能;重新尝试 Windows 10 的 WSL,顺利完成部署。
参考资料
- learn.microsoft.com/zh-cn/windo...
- developer.aliyun.com/mirror/dock...
- github.com/Mintplex-La...
- github.com/wukongdaily...
准备 WSL 环境安装 Linux 发行版
-
开启 WSL
bashEnable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
-
下载 Linux 发行版
bashInvoke-WebRequest -Uri https://aka.ms/wslubuntu2004 -OutFile Ubuntu.appx -UseBasicParsing
-
修改安装包的扩展名并启动安装文件
bashRename-Item ./Ubuntu-1804.appx ./Ubuntu.zip Expand-Archive ./Ubuntu.zip ./Ubuntu ./Ubuntu/ubuntu1804.exe
安装 Docker
-
使用镜像下载安装,详 developer.aliyun.com/mirror/dock...
bash# step 1: 安装必要的一些系统工具 sudo apt-get update sudo apt-get install ca-certificates curl gnupg # step 2: 信任 Docker 的 GPG 公钥 sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg sudo chmod a+r /etc/apt/keyrings/docker.gpg # Step 3: 写入软件源信息 echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \ "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null # Step 4: 安装Docker sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin # 安装指定版本的Docker-CE: # Step 1: 查找Docker-CE的版本: # apt-cache madison docker-ce # docker-ce | 17.03.1~ce-0~ubuntu-xenial | https://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages # docker-ce | 17.03.0~ce-0~ubuntu-xenial | https://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages # Step 2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.1~ce-0~ubuntu-xenial) # sudo apt-get -y install docker-ce=[VERSION]
-
启动服务
bash# 查看服务 ps -ef|grep # 当前用户添加到用户组 sudo usermod -aG docker $USER # 启动服务(sysvinit), WSL 中可能无法使用 systemctl 命令 sudo service docker start # 查看服务运行状态 sudo service docker status # 停止服务 sudo service docker stop
安装 anythingllm
-
如果有私有镜像库或畅通的网络环境可直接拉取,否则需要手动下载镜像文件,推荐一个免费好用的方案 github.com/wukongdaily...
-
安装 npm 和 yarn
-
加载镜像文件
bashsudo docker load -i mintplexlabs_anythingllm_latest-amd64.tar.gz
-
参考官方文档编写启动脚本
bashcat >run_anything_llm_docker.sh << EOF export STORAGE_LOCATION=$HOME/anythingllm && \ mkdir -p $STORAGE_LOCATION && \ touch "$STORAGE_LOCATION/.env" && \ sudo docker run -d -p 3001:3001 \ --cap-add SYS_ADMIN \ --user root \ -v ${STORAGE_LOCATION}:/app/server/storage \ -v ${STORAGE_LOCATION}/.env:/app/server/.env \ -e STORAGE_DIR="/app/server/storage" \ mintplexlabs/anythingllm EOF
-
特殊说明
bash# 启动配置 /.env:/app/server/.env 文件权限不够,所以相对于官方文档增加 root 用户启动 --user root # 如果 anythingllm 文件夹权限不够,需要修改权限 sudo chmod 777 anythingllm
-
启动容器
bashsh run_anything_llm_docker.sh # 检查容器状态,显示 healthy 则容器可访问 sudo docker ps # 浏览器访问,如果无法访,回到 Windows 系统打开 WSL Settings 检查网络设置 127.0.0.1:3001
提供给局域网用户访问
- 配置 Windows 防火墙
- 打开"控制面板" > "系统和安全" > "Windows Defender 防火墙">"高级设置">"入站规则"
- 添加一条新的规则,使得 3001 端口可通过,选择 TCP
-
在 Windows 上以管理员身份打开 PowerShell
bash#配置端口转发 netsh interface portproxy add v4tov4 listenport=3001 listenaddress=0.0.0.0 connectport=3001 connectaddress=127.0.0.1 # 检查端口转发是否生效 netsh interface portproxy show all # 查询本机的局域网 ip (如 192.168.0.100) ipconfig # 其他设备通过 http://192.168.0.100:3001 访问服务