欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > Dify中的docker-compose.yaml分析-web、db、redis、weaviate等

Dify中的docker-compose.yaml分析-web、db、redis、weaviate等

2025/2/24 21:03:45 来源:https://blog.csdn.net/shengshengwang/article/details/140258162  浏览:    关键词:Dify中的docker-compose.yaml分析-web、db、redis、weaviate等

本文主要介绍了web、db、redis、weaviate、sandbox和ssrf_proxy等服务的配置,除此之外,还有Qdrant(向量数据库)、Milvus(向量数据库)和Nginx(反向代理)服务不再介绍。

1.web服务:前端应用

# Frontend web application.
web:image: langgenius/dify-web:0.6.9restart: alwaysenvironment:# The base URL of console application api server, refers to the Console base URL of WEB service if console domain is# different from api or web app domain.# example: http://cloud.dify.aiCONSOLE_API_URL: ''# The URL for Web APP api server, refers to the Web App base URL of WEB service if web app domain is different from# console or api domain.# example: http://udify.appAPP_API_URL: ''# The DSN for Sentry error reporting. If not set, Sentry error reporting will be disabled.SENTRY_DSN: ''# uncomment to expose dify-web port to host# ports:#   - "3000:3000"
# Frontend web application.
web:image: langgenius/dify-web:0.6.9

使用名为 langgenius/dify-web 的 Docker 镜像,版本为 0.6.9,启动前端 Web 应用程序。

  restart: always

确保容器在任何情况下(例如崩溃、系统重启等)都自动重启。

  environment:

定义容器运行时的环境变量。

    # The base URL of console application api server, refers to the Console base URL of WEB service if console domain is# different from api or web app domain.# example: http://cloud.dify.aiCONSOLE_API_URL: ''

控制台应用程序 API 服务器的基础 URL。如果控制台域名与 API 或 Web 应用域名不同,则指向 Web 服务的控制台基础 URL。此处未设置值。

    # The URL for Web APP api server, refers to the Web App base URL of WEB service if web app domain is different from# console or api domain.# example: http://udify.appAPP_API_URL: ''

Web 应用 API 服务器的 URL。如果 Web 应用域名与控制台或 API 域名不同,则指向 Web 服务的 Web 应用基础 URL。此处未设置值。

    # The DSN for Sentry error reporting. If not set, Sentry error reporting will be disabled.SENTRY_DSN: ''

Sentry 错误报告的数据源名称。如果未设置,则禁用 Sentry 错误报告。此处未设置值。

  # uncomment to expose dify-web port to host# ports:#   - "3000:3000"

端口配置,取消注释以将 dify-web 端口暴露给主机。

  • ports:指定端口映射,例如 "3000:3000"

2.db服务:Postgres数据库

# The postgres database.
db:image: postgres:15-alpinerestart: alwaysenvironment:PGUSER: postgres# The password for the default postgres user.POSTGRES_PASSWORD: difyai123456# The name of the default postgres database.POSTGRES_DB: dify# postgres data directoryPGDATA: /var/lib/postgresql/data/pgdatavolumes:- db_data:/var/lib/postgresql/data# uncomment to expose db(postgresql) port to hostports:- "5432:5432"healthcheck:test: [ "CMD", "pg_isready" ]interval: 1stimeout: 3sretries: 30
# The postgres database.
db:image: postgres:15-alpine

使用名为 postgres 的 Docker 镜像,版本为 15-alpine,启动 PostgreSQL 数据库。

  restart: always

确保容器在任何情况下(例如崩溃、系统重启等)都自动重启。

  environment:

定义容器运行时的环境变量。

    PGUSER: postgres

默认的 PostgreSQL 用户名。

    # The password for the default postgres user.POSTGRES_PASSWORD: difyai123456

默认的 PostgreSQL 用户密码。

    # The name of the default postgres database.POSTGRES_DB: dify

默认的 PostgreSQL 数据库名称。

    # postgres data directoryPGDATA: /var/lib/postgresql/data/pgdata

PostgreSQL 数据目录。

  volumes:- db_data:/var/lib/postgresql/data

卷配置,将命名卷 db_data 挂载到容器中的 /var/lib/postgresql/data 目录,以持久化存储 PostgreSQL 数据。

  # uncomment to expose db(postgresql) port to hostports:- "5432:5432"

端口配置,取消注释以将 PostgreSQL 端口暴露给主机。

  • ports:指定端口映射,例如 "5432:5432"
  healthcheck:test: [ "CMD", "pg_isready" ]

健康检查,使用 pg_isready 命令测试 PostgreSQL 的健康状态。

    interval: 1s

健康检查的时间间隔,每 1 秒检查一次。

    timeout: 3s

健康检查的超时时间,3 秒后超时。

    retries: 30

健康检查的重试次数,最多重试 30 次。

3.redis服务:Redis缓存

# The redis cache.
redis:image: redis:6-alpinerestart: alwaysvolumes:# Mount the redis data directory to the container.- ./volumes/redis/data:/data# Set the redis password when startup redis server.command: redis-server --requirepass difyai123456healthcheck:test: [ "CMD", "redis-cli", "ping" ]# uncomment to expose redis port to host# ports:#   - "6379:6379"
# The redis cache.
redis:image: redis:6-alpine

使用名为 redis 的 Docker 镜像,版本为 6-alpine,启动 Redis 缓存服务。

  restart: always

确保容器在任何情况下(例如崩溃、系统重启等)都自动重启。

  volumes:# Mount the redis data directory to the container.- ./volumes/redis/data:/data

卷配置,将本地目录 ./volumes/redis/data 挂载到容器中的 /data 目录,以持久化存储 Redis 数据。

  # Set the redis password when startup redis server.command: redis-server --requirepass difyai123456

启动 Redis 服务器时设置密码 difyai123456

  healthcheck:test: [ "CMD", "redis-cli", "ping" ]

健康检查,使用 redis-cli ping 命令测试 Redis 的健康状态。

  # uncomment to expose redis port to host# ports:#   - "6379:6379"

端口配置,取消注释以将 Redis 端口暴露给主机。

  • ports:指定端口映射,例如 "6379:6379"

4.weaviate服务:向量数据库

# The Weaviate vector store.
weaviate:image: semitechnologies/weaviate:1.19.0restart: alwaysvolumes:# Mount the Weaviate data directory to the container.- ./volumes/weaviate:/var/lib/weaviateenvironment:# The Weaviate configurations# You can refer to the [Weaviate](https://weaviate.io/developers/weaviate/config-refs/env-vars) documentation for more information.QUERY_DEFAULTS_LIMIT: 25AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'false'PERSISTENCE_DATA_PATH: '/var/lib/weaviate'DEFAULT_VECTORIZER_MODULE: 'none'CLUSTER_HOSTNAME: 'node1'AUTHENTICATION_APIKEY_ENABLED: 'true'AUTHENTICATION_APIKEY_ALLOWED_KEYS: 'WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih'AUTHENTICATION_APIKEY_USERS: 'hello@dify.ai'AUTHORIZATION_ADMINLIST_ENABLED: 'true'AUTHORIZATION_ADMINLIST_USERS: 'hello@dify.ai'# uncomment to expose weaviate port to host# ports:#  - "8080:8080"
# The Weaviate vector store.
weaviate:image: semitechnologies/weaviate:1.19.0

使用名为 semitechnologies/weaviate 的 Docker 镜像,版本为 1.19.0,启动 Weaviate 向量存储服务。

  restart: always

确保容器在任何情况下(例如崩溃、系统重启等)都自动重启。

  volumes:# Mount the Weaviate data directory to the container.- ./volumes/weaviate:/var/lib/weaviate

卷配置,将本地目录 ./volumes/weaviate 挂载到容器中的 /var/lib/weaviate 目录,以持久化存储 Weaviate 数据。

  environment:

定义容器运行时的环境变量。

    # The Weaviate configurations# You can refer to the [Weaviate](https://weaviate.io/developers/weaviate/config-refs/env-vars) documentation for more information.QUERY_DEFAULTS_LIMIT: 25

Weaviate 配置项,设置默认查询限制为 25。

    AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'false'

禁用匿名访问。

    PERSISTENCE_DATA_PATH: '/var/lib/weaviate'

设置数据持久化路径为 /var/lib/weaviate

    DEFAULT_VECTORIZER_MODULE: 'none'

设置默认的向量化模块为 none

    CLUSTER_HOSTNAME: 'node1'

设置集群主机名为 node1

    AUTHENTICATION_APIKEY_ENABLED: 'true'

启用 API 密钥身份验证。

    AUTHENTICATION_APIKEY_ALLOWED_KEYS: 'WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih'

允许的 API 密钥为 WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih

    AUTHENTICATION_APIKEY_USERS: 'hello@dify.ai'

API 密钥用户为 hello@dify.ai

    AUTHORIZATION_ADMINLIST_ENABLED: 'true'

启用管理员列表授权。

    AUTHORIZATION_ADMINLIST_USERS: 'hello@dify.ai'

管理员列表用户为 hello@dify.ai

  # uncomment to expose weaviate port to host# ports:#  - "8080:8080"

端口配置,取消注释以将 Weaviate 端口暴露给主机。

  • ports:指定端口映射,例如 "8080:8080"

5.sandbox服务:沙盒

# The DifySandbox
sandbox:image: langgenius/dify-sandbox:0.2.0restart: alwaysenvironment:# The DifySandbox configurations# Make sure you are changing this key for your deployment with a strong key.# You can generate a strong key using `openssl rand -base64 42`.API_KEY: dify-sandboxGIN_MODE: 'release'WORKER_TIMEOUT: 15ENABLE_NETWORK: 'true'HTTP_PROXY: 'http://ssrf_proxy:3128'HTTPS_PROXY: 'http://ssrf_proxy:3128'volumes:- ./volumes/sandbox/dependencies:/dependenciesnetworks:- ssrf_proxy_network
# The DifySandbox
sandbox:image: langgenius/dify-sandbox:0.2.0

使用名为 langgenius/dify-sandbox 的 Docker 镜像,版本为 0.2.0,启动 DifySandbox 服务。

  restart: always

确保容器在任何情况下(例如崩溃、系统重启等)都自动重启。

  environment:

定义容器运行时的环境变量。

    # The DifySandbox configurations# Make sure you are changing this key for your deployment with a strong key.# You can generate a strong key using `openssl rand -base64 42`.API_KEY: dify-sandbox

DifySandbox 配置项,设置 API 密钥为 dify-sandbox。确保在部署时使用强密钥,可以使用 openssl rand -base64 42 生成。

    GIN_MODE: 'release'

设置 Gin 框架的运行模式为 release

    WORKER_TIMEOUT: 15

设置工作超时时间为 15 秒。

    ENABLE_NETWORK: 'true'

启用网络访问。

    HTTP_PROXY: 'http://ssrf_proxy:3128'

设置 HTTP 代理为 http://ssrf_proxy:3128

    HTTPS_PROXY: 'http://ssrf_proxy:3128'

设置 HTTPS 代理为 http://ssrf_proxy:3128

  volumes:- ./volumes/sandbox/dependencies:/dependencies

卷配置,将本地目录 ./volumes/sandbox/dependencies 挂载到容器中的 /dependencies 目录,以存储依赖项。

  networks:- ssrf_proxy_network

网络配置,指定此服务连接到 ssrf_proxy_network 网络。

6.ssrf_proxy服务:SSRF代理服务

# ssrf_proxy server
# for more information, please refer to
# https://docs.dify.ai/getting-started/install-self-hosted/install-faq#id-16.-why-is-ssrf_proxy-needed
ssrf_proxy:image: ubuntu/squid:latestrestart: alwaysvolumes:# pls clearly modify the squid.conf file to fit your network environment.- ./volumes/ssrf_proxy/squid.conf:/etc/squid/squid.confnetworks:- ssrf_proxy_network- default
# ssrf_proxy server
# for more information, please refer to
# https://docs.dify.ai/getting-started/install-self-hosted/install-faq#id-16.-why-is-ssrf_proxy-needed
ssrf_proxy:image: ubuntu/squid:latest

使用名为 ubuntu/squid 的 Docker 镜像,最新版本,启动 SSRF 代理服务器。更多信息请参考 Dify 文档。

  restart: always

确保容器在任何情况下(例如崩溃、系统重启等)都自动重启。

  volumes:# pls clearly modify the squid.conf file to fit your network environment.- ./volumes/ssrf_proxy/squid.conf:/etc/squid/squid.conf

卷配置,将本地目录 ./volumes/ssrf_proxy/squid.conf 挂载到容器中的 /etc/squid/squid.conf 文件。请明确修改 squid.conf 文件以适应您的网络环境。

  networks:- ssrf_proxy_network- default

网络配置,指定此服务连接到 ssrf_proxy_networkdefault 网络。

7.ssrf_proxy_network:SSRF代理网络

networks:# create a network between sandbox, api and ssrf_proxy, and can not access outside.ssrf_proxy_network:driver: bridgeinternal: true

ssrf_proxy_network 是 Docker Compose 文件中定义的一个网络。在这个网络中的服务可以相互通信,但不能访问 Docker 主机的网络。

在这个项目中,ssrf_proxy_network 用于连接 sandboxapissrf_proxy 服务。这意味着这些服务可以相互通信,但不能访问 Docker 主机的网络。这是一种安全措施,可以防止潜在的网络攻击。

ssrf_proxy 服务是一个代理服务器,用于处理来自 sandboxapi 服务的网络请求。这样,所有的网络请求都会通过 ssrf_proxy 服务,这可以提供额外的安全控制和日志记录。

internal: true 表示这个网络是内部的,这意味着这个网络中的服务不能访问 Docker 主机的网络。这是一种安全措施,可以防止潜在的网络攻击。

参考文献

[1] 为什么需要SSRF_PROXY:https://docs.dify.ai/v/zh-hans/learn-more/faq/install-faq#id-18.-wei-shi-mo-xu-yao-ssrfproxy

[2] Squid configuration directives:https://www.squid-cache.org/Doc/config/

[3] Server-side request forgery (SSRF):https://portswigger.net/web-security/ssrf

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词