Building production-ready Large Language Model (LLM) applications requires orchestrating numerous moving pieces: prompt engineering, document parsing, embedding generation, vector indexing, retrieval-augmented generation (RAG), and multi-step agent reasoning. While frameworks like LangChain and LlamaIndex provide code-level libraries, Dify provides an end-to-end, visual platform that bridges the gap between technical infrastructure and visual application development.
Self-hosting Dify gives engineering teams complete control over their sensitive documents, API keys, and workflow execution without routing proprietary business logic through third-party SaaS platforms.
Understanding the Dify Service Fleet
Unlike monolithic applications, Dify is architected as an interconnected fleet of microservices packaged via Docker Compose:
- dify-web: Next.js web application providing the drag-and-drop workflow canvas, prompt evaluation playground, and user management console.
- dify-api: Python Flask backend managing business logic, user authentication, model provider routing, and dataset orchestration.
- dify-worker: Celery asynchronous worker process that handles long-running jobs: PDF document parsing, text chunking, embedding calculations, and batch dataset synchronization.
- weaviate / qdrant: High-performance vector database storing document embeddings for hybrid full-text and semantic vector retrieval.
- dify-sandbox: Isolated Docker container that executes user-defined Python and JavaScript code nodes safely without risking host access.
Service Inventory & Resource Allocation Matrix
| Service Name | Container Port | Internal Role | Recommended Minimum RAM |
|---|---|---|---|
| nginx | 80 / 443 | Public ingress and static asset reverse proxy | 64 MB |
| dify-web | 3000 | Next.js frontend user interface | 256 MB |
| dify-api | 5001 | Core application REST API and LLM router | 512 MB - 1 GB |
| dify-worker | None (Queue) | Celery async worker for RAG chunking and batch tasks | 1 GB - 2 GB |
| db (PostgreSQL) | 5432 | Relational storage for users, apps, and chat logs | 512 MB |
| redis | 6379 | In-memory cache and Celery broker | 256 MB |
| weaviate | 8080 | Vector database indexing document embeddings | 1 GB - 2 GB |
| dify-sandbox | 8190 | Sandboxed Python/Node.js code node execution | 256 MB |
Step-by-Step Deployment Runbook
To deploy Dify on an Ubuntu 22.04 or Debian 12 host with Docker Engine and Docker Compose installed:
# 1. Clone the official Dify repository
git clone https://github.com/langgenius/dify.git
cd dify/docker
# 2. Copy the environment configuration template
cp .env.example .env
# 3. Launch the container stack in detached mode
docker compose up -d
Once deployed, verify container health by checking the status of the entire stack:
docker compose ps
All nine containers should display status Up (healthy). Navigate to http://your-server-ip to complete the initial administrator setup wizard.
- Connecting Local Ollama: To connect local Ollama models to Dify running in Docker, navigate to Settings > Model Provider > Ollama. Set the Base URL to
http://host.docker.internal:11434(or your machine's local LAN IP), neverlocalhost:11434. - Worker Concurrency Sizing: In high-throughput RAG environments, PDF document processing can back up. In
.env, increaseCELERY_WORKER_CONCURRENCY=4if your VPS has 4 or more CPU cores available. - Storage Volume Persistence: Ensure
dify/docker/volumesis included in your daily backup snapshots. It houses your PostgreSQL database, Redis keys, uploaded knowledge files, and Weaviate vector indices.
Do not attempt to run Dify on a VPS with less than 4 GB of RAM (8 GB is strongly recommended). Weaviate and the Celery worker will suffer out-of-memory (OOM) crashes during concurrent PDF document chunking if memory headroom is insufficient.
Conclusion & Next Steps
Dify stands out as the most mature open-source platform for orchestrating LLM workflows, visual agents, and knowledge-base retrieval. By hosting it on your own servers, you combine enterprise-grade AI capabilities with total data sovereignty.
- Dify Official Documentation — Architecture, setup parameters, and model configuration.
- Dify GitHub Repository — Source code, Docker Compose templates, and releases.
- Dify Sandbox Repository — Secure code execution container specifications.
Discussion & Issues
Comments
Post a Comment