Dify Deployment Options: Docker, Cloud & Kubernetes
A detailed comparison of Dify Cloud, Dify Docker deployment (Compose), and Kubernetes modes, with expert configuration advice.
Dify Deployment Modes Guide
Dify offers three core usage modes to suit different needs:
- Dify Cloud (SaaS): Ready-to-use, maintenance-free.
- Private Deployment (Docker Compose): Ideal for small to medium-scale projects or POC phases.
- Enterprise Cluster Deployment (Kubernetes/Helm): Best for high-availability, large-scale production environments.
Deployment Modes Comparison
| Feature | Dify Cloud (SaaS) | Docker Compose (Private) | Kubernetes (Enterprise) |
|---|---|---|---|
| Use Case | Fast POC, non-sensitive business, no DevOps team | Internal tools, sensitive data, small-medium production | Large-scale public services, high availability, multi-tenant |
| Data Sovereignty | Data stored on Dify Cloud | Data fully localized | Data fully localized |
| Infra Cost | Usage-based / Subscription | Self-provided server resources | Self-provided cluster & cloud services |
| Ops Complexity | Zero maintenance | Medium (Single machine management) | High (Requires K8s expertise) |
| Scalability | Dependent on platform quota | Limited by single machine capacity | Native elastic scaling (HPA) |
| Compliance | SOC2 (Platform-dependent) | Full control, easy GDPR/Compliance | Full control, complex network isolation |
For detailed differences and pricing, please refer to: Dify Pricing
1. Dify Cloud (SaaS)
Before deciding on a private deployment, Dify Cloud (dify.ai) is an excellent way to start. It provides the same functional experience as the open-source version but eliminates the burden of infrastructure maintenance.
Getting started is easy:
-
Visit dify.ai and click Get Started.

-
You can log in using Email, Google, or GitHub.

-
After logging in, you'll enter the dashboard and can start your Dify journey immediately.
2. Private Deployment via Docker Compose
For developers with technical expertise or projects requiring data privacy, Docker Compose is the standard and efficient choice.
2.1 Infrastructure & Environment Tuning
Dify includes several memory-intensive components. Insufficient resources can lead to Out-Of-Memory (OOM) crashes.
2.1.1 Hardware Base Baseline
- CPU: Minimum 2 vCPU; 4 vCPU recommended for production.
- RAM: Minimum 4GB; 8GB recommended (especially if using a local vector database).
- Disk: SSD recommended, with at least 50GB reserved in the root partition.
2.1.2 Software Dependencies
- Docker Engine: Version >= 19.03.
- Docker Compose: Use V2 (command:
docker compose). - System Parameters: Increase
vm.max_map_countfor components like Weaviate.sysctl -w vm.max_map_count=262144 echo "vm.max_map_count=262144" >> /etc/sysctl.conf
2.2 Deployment Process
Step 1: Get Source Code & Lock Version Always use a Tagged version in production for stability.

git clone https://github.com/langgenius/dify.git
cd dify/docker
latest_tag=$(curl -s https://api.github.com/repos/langgenius/dify/releases/latest | jq -r .tag_name)
git checkout $latest_tagStep 2: Environment Configuration
cp .env.example .envThe following is a list of key variables to note during deployment:
| Module | Variable | Recommended Configuration |
|---|---|---|
| Security | SECRET_KEY | High Risk. Used for session and database encryption. Run openssl rand -base64 42 to generate. If leaked, system security is compromised. |
| Web Access | APP_WEB_URL | Full frontend URL (e.g., https://ai.corp.com). Used for OAuth validation and sharing links. Misconfiguration causes SSO failure or broken images. |
| Web Access | COOKIE_DOMAIN | Set to top-level domain (e.g., .corp.com) if frontend/backend are on different subdomains to share cookies. |
| Database | DB_HOST | Default is db (container name). Use RDS IP/Domain for external databases. |
| Redis | REDIS_PASSWORD | Default is empty. Must set a strong password for production to prevent unauthorized access. |
| Vector DB | VECTOR_STORE | Default is weaviate. Can be changed to milvus with proper parameters. Sync changes with docker-compose.yaml to disable unused containers. |
| Performance | GUNICORN_WORKERS | Number of API workers. Default 1. Recommended: CPU cores * 2 + 1. |
| Performance | CELERY_WORKER_AMOUNT | Concurrent async tasks. Increasing this speeds up ingestion but consumes more RAM. |
| Storage | STORAGE_TYPE | Default is local. Strongly recommended to use s3 for production. |
Modify .env to configure your database, Redis, and storage.
Step 3: Start & Health Check
docker compose up -d
docker compose psMonitor the api, worker, and db containers. For troubleshooting, check logs: docker compose logs -f api.
2.3 Advanced Enterprise Configuration: External Middleware
In production, it is best practice to "externalize" stateful services.
2.3.1 Connecting External PostgreSQL & Redis
Point your .env file to your existing high-availability clusters. Dify runs flask db upgrade automatically on startup.
2.3.2 S3 Object Storage (Key to Persistence)
Set STORAGE_TYPE=s3 and configure your S3-compatible credentials. This makes your application "stateless," simplifying horizontal scaling and migration.
3. Enterprise Deployment via Kubernetes
For scaling to thousands of users or maintaining 99.9% SLA, Kubernetes (K8s) is the preferred solution.
3.1 Architecture Planning
- Stateless Services (Deployments):
dify-api,dify-worker,dify-web. Use HPA for automatic scaling. - Stateful Services (External): Strictly avoid running core databases inside K8s in production. Use managed services like AWS RDS, ElastiCache, or managed vector stores.
3.2 Helm Chart Deployment
helm repo add dify https://borispolonsky.github.io/dify-helm
helm repo updateCustom values.yaml:
Create a production-values.yaml to disable internal databases, connect to external instances, and set resource limits and autoscaling policies.
Deployment & Initialization:
helm upgrade --install dify dify/dify -f production-values.yaml --namespace dify-prod --create-namespaceAfter deployment, manually trigger the database migration:
API_POD=$(kubectl get pods -n dify-prod -l app.kubernetes.io/component=api -o jsonpath='{.items.metadata.name}')
kubectl exec -it $API_POD -n dify-prod -- flask db upgradeAppendix: Dify Microservice Architecture
The core of Dify is built with several microservices:
- API Service (Flask): The brain, handling HTTP requests, logic, and LLM interactions.
- Worker Service (Celery): The muscle, handling tasks like document parsing, embeddings, and Agent reasoning.
- Web Service (Next.js): The UI, providing a visual Studio for app orchestration.
- Redis: Acts as a message broker and cache.
- PostgreSQL: Stores metadata (app configs, logs, user data).
- Vector Database: High-dimensional vector storage (Weaviate, Qdrant, etc.).
- Object Storage (S3): Stores unstructured data like uploaded files.
- Sandbox: A secure environment for code execution.