ChinaAgentchinaagent.ai
Categories
Tutorial· ChinaAgent 编辑部

Self-hosting Dify: from zero to a working platform with Docker Compose

One 2C4G box, four commands, and you have your own agent platform — plus the settings to change and the pitfalls to avoid.

Prerequisites

  • A Linux server or local machine with 2 cores and 4 GB RAM or more (a home NAS works)
  • Docker 24+ and Docker Compose v2 installed
  • Network access to GitHub (source) and Docker Hub (images)

Start with four commands

The official Dify repository ships a complete Docker Compose setup. Clone it, enter the docker directory, copy the env template, and start:

git clone https://github.com/langgenius/dify.git
cd dify/docker
cp .env.example .env
docker compose up -d

The first start pulls a dozen images. Once all containers are up, open http://localhost/install (your server IP or domain instead) to create the admin account. Dify uses port 80 by default.

Three settings to change before going live

  • EXPOSE_NGINX_PORT: change it in .env if port 80 is taken or you prefer another port, then docker compose down && docker compose up -d
  • SECRET_KEY: replace with a long random string in .env — it encrypts sessions and credentials
  • Model provider keys: configure under Settings → Model Provider, e.g. DeepSeek or SiliconFlow API keys, or a local Ollama endpoint

Common pitfalls

  • Port conflict: if nginx or another service holds port 80, change EXPOSE_NGINX_PORT instead of container-internal ports
  • Slow image pulls in China: configure a Docker registry mirror, or pull on a well-connected machine and export/import
  • Slow first start: the vector DB initializes on first boot — wait for all healthchecks to turn healthy before touching anything
  • Upgrades: git pull, then docker compose pull && docker compose up -d; back up database volumes first

Next steps

With a model configured, build a knowledge-base Q&A app first to walk the full upload → embedding → answering flow, then try workflow orchestration. For the hosted-vs-self-hosted trade-off, see our compare page; for Coze as an alternative, see the Coze Studio entry.

This tutorial covers the standard open-source Dify install; version specifics follow the official docs.

Products covered

  • DifyOpen-source LLM app and agent platform with self-hosting.
  • Coze StudioThe open-source edition of Coze: Coze's building experience on your own server.

Articles