Dify前端二改源码启动

后端服务通过docker启动

1、克隆Dify代码仓库到本地(单纯启动前端是访问不到后台服务)

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

2、进入 Dify 源代码的 Docker 目录

cd dify/docker

3、复制环境配置文件

cp .env.example .env

4、启动dockers容器
根据你系统上的 Docker Compose 版本,选择合适的命令来启动容器。你可以通过 $ docker compose version 命令检查版本,详细说明请参考 Docker 官方文档

  • 如果版本是 Docker Compose V2,使用以下命令:
docker compose up -d
// 或者
docker-compose -f docker-compose.dify-plus.yaml up -d

    •  如果版本是 Docker Compose V1,使用以下命令:
    docker-compose up -d

    运行命令后,你应该会看到类似以下的输出,显示所有容器的状态和端口映射:(如果启动失败,那就是,你电脑中有什么服务正在占用80端口,需要关闭掉,然后回来重新启动)

    [+] Running 11/11
     ✔ Network docker_ssrf_proxy_network  Created                                                                 0.1s 
     ✔ Network docker_default             Created                                                                 0.0s 
     ✔ Container docker-redis-1           Started                                                                 2.4s 
     ✔ Container docker-ssrf_proxy-1      Started                                                                 2.8s 
     ✔ Container docker-sandbox-1         Started                                                                 2.7s 
     ✔ Container docker-web-1             Started                                                                 2.7s 
     ✔ Container docker-weaviate-1        Started                                                                 2.4s 
     ✔ Container docker-db-1              Started                                                                 2.7s 
     ✔ Container docker-api-1             Started                                                                 6.5s 
     ✔ Container docker-worker-1          Started                                                                 6.4s 
     ✔ Container docker-nginx-1           Started                                                                 7.1s

     最后检查是否所有容器都正常运行:

    docker compose ps

    在这个输出中,你应该可以看到包括 3 个业务服务 api / worker / web,以及 6 个基础组件 weaviate / db / redis / nginx / ssrf_proxy / sandbox

    NAME                  IMAGE                              COMMAND                   SERVICE      CREATED              STATUS                        PORTS
    docker-api-1          langgenius/dify-api:0.6.13         "/bin/bash /entrypoi…"   api          About a minute ago   Up About a minute             5001/tcp
    docker-db-1           postgres:15-alpine                 "docker-entrypoint.s…"   db           About a minute ago   Up About a minute (healthy)   5432/tcp
    docker-nginx-1        nginx:latest                       "sh -c 'cp /docker-e…"   nginx        About a minute ago   Up About a minute             0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp
    docker-redis-1        redis:6-alpine                     "docker-entrypoint.s…"   redis        About a minute ago   Up About a minute (healthy)   6379/tcp
    docker-sandbox-1      langgenius/dify-sandbox:0.2.1      "/main"                   sandbox      About a minute ago   Up About a minute             
    docker-ssrf_proxy-1   ubuntu/squid:latest                "sh -c 'cp /docker-e…"   ssrf_proxy   About a minute ago   Up About a minute             3128/tcp
    docker-weaviate-1     semitechnologies/weaviate:1.19.0   "/bin/weaviate --hos…"   weaviate     About a minute ago   Up About a minute             
    docker-web-1          langgenius/dify-web:0.6.13         "/bin/sh ./entrypoin…"   web          About a minute ago   Up About a minute             3000/tcp
    docker-worker-1       langgenius/dify-api:0.6.13         "/bin/bash /entrypoi…"   worker       About a minute ago   Up About a minute             5001/tcp

    你可以先前往管理员初始化页面设置设置管理员账户:

    # 本地环境
    http://localhost/install
    
    # 服务器环境
    http://your_server_ip/install

    Dify 主页面:

    # 本地环境,这里只是在线访问,并不是你的前端源码环境
    http://localhost:80
    
    # 服务器环境
    http://your_server_ip

    启动关闭Dify(以防占用端口资源)

    # 关闭
    docker compose down
    # 启动
    docker compose up -d

     前端Web源码启动

     启动步骤(前面已经克隆了代码就不需要再克隆了)

    1、进入 Web 目录

    cd web

     2、安装依赖包

    # 这个项目其实指定了pnpm工具去管理,想用其它的管理工具的话需要改动package.json文件以及其它文件,建议直接用pnpm
    pnpm install

     3、配置环境变量。在当前目录下创建文件 .env.local,并复制.env.example中的内容。根据需求修改这些环境变量的值:(不要复制官网的,复制我这里的就可以。)

    # For production release, change this to PRODUCTION
    NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT
    # The deployment edition, SELF_HOSTED
    NEXT_PUBLIC_EDITION=SELF_HOSTED
    # The base URL of console application, refers to the Console base URL of WEB service if console domain is
    # different from api or web app domain.
    # example: http://cloud.dify.ai/console/api
    NEXT_PUBLIC_API_PREFIX=http://localhost/console/api
    # The URL for Web APP, refers to the Web App base URL of WEB service if web app domain is different from
    # console or api domain.
    # example: http://udify.app/api
    NEXT_PUBLIC_PUBLIC_API_PREFIX=http://localhost/api
    
    # SENTRY
    NEXT_PUBLIC_SENTRY_DSN=
    NEXT_PUBLIC_SENTRY_ORG=
    NEXT_PUBLIC_SENTRY_PROJECT=

    下面是官网给的信息,其实不是start这样起不来的,安装完依赖直接 pnpm run dev就行

    4、构建代码

    npm run build

    构建失败一般就是内存不足,增加node内存就行

    NODE_OPTIONS="--max-old-space-size=4096" npm run build
    

    5、启动 web 服务

    npm run start
    # or
    yarn start
    # or
    pnpm start

    正常启动后,终端会输出如下信息:

    ready - started server on 0.0.0.0:3000, url: http://localhost:3000
    warn  - You have enabled experimental feature (appDir) in next.config.js.
    warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
    info  - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值