AI Application DeploymentAI 应用部署

Deploy Dify with Docker Compose: A Production-minded Guide使用 Docker Compose 部署 Dify:面向生产的完整指南

Install Dify with its official Docker Compose workflow, verify the services, protect the installation screen and prepare a reverse proxy before exposing it publicly.按照 Dify 官方 Docker Compose 流程完成安装、服务检查、初始化页面保护和反向代理准备,再安全地开放公网访问。

Difficulty 3/5难度 3/535 minutes35 分钟Linux, Docker and Docker Compose; Dify documents a minimum of 2 CPU cores and 4 GiB RAMLinux、Docker 与 Docker Compose;Dify 官方最低要求为 2 核 CPU、4 GiB 内存

What you are building

Dify is an open-source platform for building AI applications, workflows, agents and retrieval-augmented generation services. This guide follows the official Docker Compose path and adds the checks needed before a public launch.

Before you begin

Use a supported Linux distribution and a user that can run Docker.
Point a domain to the server before configuring HTTPS.
Keep model-provider API keys outside source control.
Dify documents a minimum of 2 CPU cores and 4 GiB of RAM. Real workloads may need more memory because the stack includes several services.

Deployment plan

The official repository contains the Compose configuration under the docker directory. Copy the example environment file, review secrets and exposed ports, start the stack, then finish setup through the installation page.

Production checks

Do not leave the initial installation route unattended on a public IP.
Put Caddy or another reverse proxy in front of Dify and enable HTTPS.
Back up the database, uploaded files and the environment configuration.
Monitor disk usage and container health before adding users.
Start with a small test workload and scale after observing memory use.

Sources and next steps

Review the official Dify repository for current commands and release notes. Compare a suitable AI application server plan before deployment.

你将部署什么

Dify 是用于构建 AI 应用、工作流、智能体和检索增强生成服务的开源平台。本教程遵循官方 Docker Compose 安装路径,并补充公网发布前必须完成的检查。

开始前准备

使用受支持的 Linux 发行版,并确保当前用户可以运行 Docker。
配置 HTTPS 前,先将域名解析到服务器。
模型服务商 API 密钥不要提交到代码仓库。
Dify 官方给出的最低要求为 2 核 CPU 和 4 GiB 内存。由于完整系统包含多个服务,真实业务通常需要更多内存余量。

部署思路

官方仓库的 docker 目录包含 Compose 配置。复制示例环境文件,检查密钥和暴露端口,启动服务后,再通过安装页面完成初始化。

生产环境检查

不要让首次安装页面长期暴露在无人管理的公网 IP 上。
使用 Caddy 或其他反向代理,并启用 HTTPS。
定期备份数据库、上传文件和环境配置。
添加用户前先监控磁盘空间和容器健康状态。
从小规模测试开始,根据实际内存占用再扩容。

资料来源与下一步

请在执行前查看 Dify 官方仓库 的最新命令和版本说明,并在部署前比较合适的 AI 应用服务器方案

Deployment steps部署步骤

01

Install Docker and verify Compose安装 Docker 并验证 Compose

Install Docker from the official Docker documentation for your distribution. Confirm both the engine and Compose plugin are available.

按照 Docker 官方文档为当前发行版安装 Docker,并确认 Docker 引擎和 Compose 插件都可使用。

docker --version
docker compose version
02

Clone the official Dify repository克隆 Dify 官方仓库

Clone the repository and enter the Docker deployment directory. Review the release or tag you intend to operate before going live.

克隆官方仓库并进入 Docker 部署目录。正式上线前,应确认准备长期运行的版本或标签。

git clone https://github.com/langgenius/dify.git
cd dify/docker
03

Create and review the environment file创建并检查环境配置

Copy the provided example. Replace default secrets, confirm URLs and keep the resulting file out of public repositories.

复制官方示例文件,替换默认密钥并确认访问地址。生成的环境文件不得进入公开仓库。

cp .env.example .env
chmod 600 .env
04

Start the application stack启动应用服务

Start the services in detached mode, then review container status and recent logs before opening the setup page.

以后台方式启动服务,并在打开初始化页面前检查容器状态和近期日志。

docker compose up -d
docker compose ps
docker compose logs --tail=100
05

Complete setup and add HTTPS完成初始化并配置 HTTPS

Open the documented installation route, create the first administrator, then place the service behind Caddy. Restrict direct access to internal service ports.

访问官方说明中的安装路径,创建首个管理员,然后通过 Caddy 反向代理服务,并限制外部直接访问内部端口。

# Example Caddy target
# dify.example.com {
#   reverse_proxy 127.0.0.1:80
# }