Dify部署

1.官网部署文档

https://docs.dify.ai/zh-hans/getting-started/install-self-hosted/docker-compose

2.Dify最新版本查看

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

3.部署Dify

3.1克隆 Dify 源代码至本地环境

git clone https://github.com/langgenius/dify.git --branch 1.1.3

3.2 启动 Dify

  • 进入 Dify 源代码的 Docker 目录
cd dify/docker
  • 复制环境配置文件
cp .env.example .env
  • 启动 Docker 容器,根据你系统上的 Docker Compose 版本,选择合适的命令来启动容器。你可以通过 $ docker compose version 命令检查版本,详细说明请参考 Docker 官方文档:
#如果版本是 Docker Compose V2,使用以下命令:
docker compose up -d

#如果版本是 Docker Compose V1,使用以下命令:
docker-compose up -d
  • 运行之后看状态,发现docker-api-1、docker-worker-1、docker-sandbox-1没有启动成功,查看日志报错如下:
Aborted!
Running migrations
OpenBLAS blas_thread_init: pthread_create failed for thread 1 of 8: Operation not permitted
OpenBLAS blas_thread_init: RLIMIT_NPROC 1048576 current, 1048576 max
OpenBLAS blas_thread_init: pthread_create failed for thread 2 of 8: Operation not permitted
OpenBLAS blas_thread_init: RLIMIT_NPROC 1048576 current, 1048576 max
OpenBLAS blas_thread_init: pthread_create failed for thread 3 of 8: Operation not permitted
OpenBLAS blas_thread_init: RLIMIT_NPROC 1048576 current, 1048576 max
OpenBLAS blas_thread_init: pthread_create failed for thread 4 of 8: Operation not permitted
OpenBLAS blas_thread_init: RLIMIT_NPROC 1048576 current, 1048576 max
OpenBLAS blas_thread_init: pthread_create failed for thread 5 of 8: Operation not permitted
OpenBLAS blas_thread_init: RLIMIT_NPROC 1048576 current, 1048576 max
OpenBLAS blas_thread_init: pthread_create failed for thread 6 of 8: Operation not permitted
OpenBLAS blas_thread_init: RLIMIT_NPROC 1048576 current, 1048576 max
OpenBLAS blas_thread_init: pthread_create failed for thread 7 of 8: Operation not permitted
OpenBLAS blas_thread_init: RLIMIT_NPROC 1048576 current, 1048576 max
  • 根据日志可以看出
(1)根据日志可以看到在 OpenBLAS 线程创建失败(pthread_create failed),导致服务崩溃(Aborted!)。
(2)0Operation not permitted是权限问题:容器可能缺少某些权限(如 CAP_SYS_RESOURCE),导致无法创建足够线程。
  • 修改启动docker-compose.yaml文件中,docker-api-1、docker-worker-1、docker-sandbox-1的 ulimits 限制或者给予privileged特权权限,我使用privileged模式
#方法 1:调整容器 ulimit 限制
在 docker-compose.yml 中为服务增加资源限制配置:
services:
  your_service:
    image: your_image
    ulimits:
      nproc: 65535  # 提高进程/线程数限制
      nofile:
        soft: 20000
        hard: 40000

	  
#方法 2:以特权模式运行容器
如果 ulimit 调整无效,尝试赋予容器特权(需谨慎):
services:
  your_service:
    image: your_image
    privileged: true  # 允许容器访问宿主机资源
  • 重新运行Dify
docker-compose down
docker-compose up -d
  • 运行状态查看
[root@localhost Dify]# docker-compose ps
NAME                     IMAGE                                       COMMAND                  SERVICE         CREATED          STATUS                    
docker-api-1             langgenius/dify-api:1.1.3                   "/bin/bash /entrypoi…"   api             31 minutes ago   Up 31 minutes             
docker-db-1              postgres:15-alpine                          "docker-entrypoint.s…"   db              31 minutes ago   Up 31 minutes (healthy)   
docker-nginx-1           nginx:latest                                "sh -c 'cp /docker-e…"   nginx           31 minutes ago   Up 31 minutes              
docker-plugin_daemon-1   langgenius/dify-plugin-daemon:0.0.6-local   "/bin/bash -c /app/e…"   plugin_daemon   31 minutes ago   Up 31 minutes             
docker-redis-1           redis:6-alpine                              "docker-entrypoint.s…"   redis           31 minutes ago   Up 31 minutes (healthy)   
docker-sandbox-1         langgenius/dify-sandbox:0.2.11              "/main"                  sandbox         31 minutes ago   Up 31 minutes (healthy)   
docker-ssrf_proxy-1      ubuntu/squid:latest                         "sh -c 'cp /docker-e…"   ssrf_proxy      31 minutes ago   Up 31 minutes            
docker-weaviate-1        semitechnologies/weaviate:1.19.0            "/bin/weaviate --hos…"   weaviate        31 minutes ago   Up 31 minutes             
docker-web-1             langgenius/dify-web:1.1.3                   "/bin/sh ./entrypoin…"   web             31 minutes ago   Up 31 minutes             
docker-worker-1          langgenius/dify-api:1.1.3                   "/bin/bash /entrypoi…"   worker          31 minutes ago   Up 31 minutes   

4.访问 Dify

  • 你可以先前往管理员初始化页面设置设置管理员账户:
# 服务器环境
http://your_server_ip/install
  • Dify 主页面:
# 服务器环境
http://your_server_ip
  • 页面展示:

 

posted @ 2025-03-26 13:18  Leonardo-li  阅读(1152)  评论(0)    收藏  举报