demo_win10配置WSL、DockerDesktop环境,本地部署Dify,ngrok公网测试

发布于:2025-06-04 ⋅ 阅读:(45) ⋅ 点赞:(0)

win10配置WSL、DockerDesktop环境,本地部署Dify,ngrok分享测试

一、配置WSL

1.1 开启Hyper-V

安装WSL2首先要保证操作系统可以开启hyper-v功能,默认支持开启hyper-v的版本为:Windows11企业版、专业版或教育版,而家庭版是不支持开启的,但是我们如果是家庭版,可以自行安装相关组件来开启hyper-v功能。

w11家庭中文版开启hyper-v步骤:

1.创建hyper-v.bat文件,将以下代码复制并保存;

pushd "%\~dp0"
dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt
for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"
del hyper-v.txt
Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL

2.已管理员身份运行hyper-v.bat文件,等待执行,提示输入【y】后重启计算机;

3.重启后,可以在【控制面板-程序功能-启用或关闭Windows功能】列表勾选Hyper-V;

在这里插入图片描述

非家庭版可直接在【控制面板-程序功能-启用或关闭Windows功能】开启Hyper-V;

1.2 启用window子系统及虚拟化

管理员身份运行 powershell,执行如下命令启用文win子系统及虚拟化:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

1.3 安装WSL2

基于WSL2技术来使用Docker Desktop,先安装WSL2

直接省事选择,在线安装

wsl -l -o  # wsl --list --online
wsl --install -d Ubuntu-20.04
wsl  -l  -v  

安装过程也会有要求输入用户名和密码;

安装成功,wsl -l -v 显示, ubuntu应该已经挂载到wsl:

在这里插入图片描述

另外也可手动安装并安装到其他盘,可参考文档:

https://blog.csdn.net/daodaipsrensheng/article/details/143154066

1.4 文件传输:

wsl访问win,/mnt下有C, D盘;

win访问wsl,可以用【电脑-Linux】可以直接打开wsl文件

1.5 为Ubuntu安装docker

为刚刚安装的ubuntu安装依赖:

sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common

-- 信任 Docker 的 GPG 公钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

-- 对于 amd64 架构的计算机,添加软件仓库:
sudo add-apt-repository \
   "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
   $(lsb_release -cs) \
   stable"-- 安装docker
sudo apt-get update
sudo apt-get install docker-ce

启动docker:

sudo service docker start 
docker images
docker search nginx

测试docker:

docker run hello-world
docker pull nginx
docker run --name nginx -p 8080:80 -d nginx

其他:

wsl官方文档,常用命令等

https://learn.microsoft.com/zh-cn/windows/wsl/basic-commands

报错记录:

wsl: 检测到 localhost 代理配置,但未镜像到 WSL。NAT 模式下的 WSL 不支持 localhost 代理。

二、安装、配置DockerDesktop

2.1 安装DockerDesktop

Docker默认安装路径为C盘:

C:\你的用户名\AppData\Local\Docker\wsl

但是docker后续镜像占用磁盘较多,这里把Docker安装到其他盘;

步骤如下:

  1. 官网下载Docker Desktop Installer.exe

  2. 管理员身份运行cmd,进入到Docker Desktop Installer.exe目录

  3. 在命令行提示符运行如下代码,具体安装路径自行修改;

    start /w "" "Docker Desktop Installer.exe" install -accept-license --installation-dir="D:\Docker" --wsl-default-data-root="D:\Docker\data" --windows-containers-default-data-root="D:\\Docker"
    

    note:

    D:\Docker 是Docker Desktop 安装程序的安装目录;

    D:\Docker\data是Docker存放是Docker 用于存储镜像、容器、卷等数据的目录;

    D:\Docker,表示在 Windows 操作系统中,Docker 程序将被安装在 D 盘一个名为 Docker 的文件夹中,记得双斜杠。
    在运行代码前,一定要提前手动创建好对应文件夹,不然会报错。

    检查实际路径:

在这里插入图片描述

2.1 配置DockerDesktop

配置国内镜像源

在如下位置配置国内镜像源,

在这里插入图片描述

镜像源参考使用:

"registry-mirrors": [
    "https://docker.1ms.run",
    "https://docker.xuanyuan.me",
    "https://dislabaiot.xyz",
    "https://hub.rat.dev",
    "https://doublezonline.cloud",
    "https://xdark.top",
    "https://dev.xuanyuan.dev",
    "https://docker.anyhub.us.kg",
    "https://dockerhub.jobcher.com",
    "https://dockerhub.icu",
    "https://hub-mirror.c.163.com",
    "https://mirror.ccs.tencentyun.com",
    "https://mirrors.aliyun.com"
  ]

报错记录:

实测wsl2.5.1、2.5.7版本与DockerDesktop4.41.2版本无法兼容使用,报错:Unknown key ‘automount.crossDistro’ in /etc/wsl.conf:3

/etc/wsl.conf内容如下:

[automount]
root = /mnt/host
crossDistro = true
options = "metadata"
[interop]
enabled = true

解决方案:

参考:

https://github.com/microsoft/WSL/issues/12711#issuecomment-2752958025

https://github.com/docker/for-win/issues/14704

通过wsl降版本2.4.x解决

下载地址:WSL-Releases

DockerDesktop无法启动,多次重复安装依旧;

解决方案

首先确定wsl能正常启动;

删除未卸载干净文件,否则换路径安装;

三、本地部署dify应用尝鲜

前面第一步和第二步配置好WSL2和docker后,现在 基于dify部署一个简单的文档解析应用;

部署dify系统要求:

  • CPU >= 2 Core
  • RAM >= 4 GiB

3.1 克隆dify仓库:

git clone https://github.com/langgenius/dify.git

3.2 快速启动部署:

docker-compose.yml 文件为官方给定yaml配置文件,启动docker后执行如下命令:

cd docker
cp .env.example .env
docker compose up -d

docker compose up -d 命令执行完,会pull相关镜像并启动容器,启动成功截图如下:
在这里插入图片描述

启动成功后,在浏览器上访问 http://localhost/install 进入 Dify 控制台即可操作

创建知识库与创建应用基于UI操作,可自查文档

简单搭建的基于知识库的文档解析助手如下:
在这里插入图片描述

参照README: https://github.com/langgenius/dify/blob/main/README_CN.md

四、ngrok分享

dify基于cloud搭建应用文档解析很慢,在本地部署可以快速构建知识库,本地部署后可以通过ngrok将本地部署服务发布公网使用;

如下图,三步骤生成临时公网ip:
在这里插入图片描述

第2步是需要命令提示符cd到ngrok下载目录执行,且默认dify端口为80,配置文件为.env.example
在这里插入图片描述

公网ip生成成功页面如下:

标红即为临时公网地址
分享给别人用,需要邮箱+密码登录

ref: Setup - ngrok

Ngrok 内网穿透教程(Windows 系统


网站公告

今日签到

点亮在社区的每一天
去签到