Complete Guide to Deploying and Using Dify Locally With Docker
Building production-ready AI applications no longer requires a team of machine learning engineers. Dify — whose name comes from "Do It For You" — is an open-source platform that lets you visually orchestrate AI models, connect data sources, and define processing pipelines on a drag-and-drop canvas. Whether you want a customer service chatbot, an internal knowledge assistant, or a multi-step research agent, Dify provides the building blocks to go from idea to working software in minutes rather than weeks.
This tutorial walks you through everything you need to know to get Dify running on your own machine. We will cover system requirements, a step-by-step Docker Compose deployment, post-install configuration, your first application build, and advanced features like knowledge bases, workflows, and MCP tool integration. By the end, you will have a fully functional local AI application platform ready for real projects.
Understanding Dify's Architecture
Before typing any commands, it helps to understand what runs under the hood. Dify is not a single monolithic application. It is a collection of cooperating services, each with a distinct responsibility.
Core Services
When you deploy Dify with Docker Compose, five core services start automatically:
- API — The backend REST API server (Flask-based) that handles all business logic, authentication, and orchestration.
- Worker — A Celery asynchronous task worker that processes long-running jobs such as document embedding, batch generation, and background workflows.
- Worker Beat — The Celery beat scheduler that triggers periodic tasks like cleaning expired sessions or scheduled indexing.
- Web — The Next.js frontend application that serves the visual studio interface you interact with in the browser.
- Plugin Daemon — A dedicated service that manages the lifecycle and execution of Dify plugins, including custom tools and model providers.
Dependency Components
In addition to the core services, six infrastructure components are launched:
- PostgreSQL (
db_postgres) — The primary relational database storing users, applications, conversations, and metadata. - Redis — An in-memory store used for caching, session management, and as a Celery message broker.
- Weaviate — The default vector database for storing and检索 embeddings that power Retrieval-Augmented Generation (RAG).
- Nginx — A reverse proxy that routes external HTTP/HTTPS traffic to the appropriate internal services.
- SSRF Proxy — A Squid-based proxy that guards against Server-Side Request Forgery attacks when Dify fetches external URLs.
- Sandbox — An isolated execution environment for running user-submitted code safely (used in code nodes within workflows).
Understanding this architecture is crucial when troubleshooting. If your knowledge base indexing stalls, for example, you should check the Worker logs, not the API logs.
System Requirements and Prerequisites
Hardware Requirements
Dify is relatively lightweight for a development environment, but it does run over a dozen containers simultaneously. Here are the minimum and recommended specifications:
- CPU: Minimum 2 cores. Recommended 4+ cores for smooth operation, especially when running local models through Ollama alongside Dify.
- RAM: Minimum 4 GiB. Recommended 8 GiB or more. The vector database, Redis, and multiple application containers together consume significant memory.
- Disk: At least 20 GiB of free space. Docker images, vector data, and uploaded documents accumulate over time.
Software Requirements by Operating System
macOS (10.14 or later)
Install Docker Desktop for Mac, which includes Docker Compose. Ensure the Docker virtual machine is configured with at least 2 virtual CPUs and 8 GiB of memory. You can adjust these settings in Docker Desktop → Settings → Resources.
Linux (Ubuntu, Debian, CentOS, etc.)
You need Docker Engine 19.03 or later and Docker Compose 2.24.0 or later. Most modern Linux distributions can install these through their package managers. Verify your versions:
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
Windows (with WSL 2)
Install Docker Desktop for Windows with the WSL 2 backend enabled. An important caveat: store your Dify source code and any bind-mounted data inside the Linux file system (e.g., under your WSL home directory), not on the Windows file system. Cross-filesystem bind mounts suffer from severe performance penalties and can cause file-watching issues.
LLM API Key
While Dify itself is free and open-source, you need access to at least one large language model. Options include:
- Cloud providers: OpenAI (GPT-4o, GPT-4o-mini), Anthropic (Claude), Google (Gemini), DeepSeek, Zhipu AI (GLM), and many others.
- Local models: Ollama running on the same machine or a nearby server. This is ideal for air-gapped environments or when you want zero per-token costs.
Have your API key ready before proceeding to the configuration section.
Step-by-Step Deployment With Docker Compose
This is the recommended and most straightforward deployment method. Follow these steps carefully.
Step 1: Clone the Repository
Clone the Dify source code at the latest stable release:
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
Note: If you are behind a corporate firewall or in a region with unreliable GitHub access, consider using a mirror or proxy. You can also download the release archive directly from the GitHub releases page.
Step 2: Prepare the Environment File
Navigate to the Docker directory and create your environment configuration:
| 1 | |
| 2 | |
| 3 | |
| 4 | |
The .env file controls every aspect of your deployment. We will customize it in the next section, but the defaults are sufficient to get started.
Step 3: Launch All Services
Start the containers in detached mode:
| 1 | |
This command downloads the necessary images and starts all services. The first run will take several minutes depending on your internet speed. You should see output similar to:
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
Step 4: Verify the Deployment
Check that all containers are running:
| 1 | |
Every container should show a status of Up or healthy:
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
If any container shows Exited or Restarting, check its logs:
| 1 | |
| 2 | |
Step 5: Access the Web Interface
Open your browser and navigate to:
| 1 | |
The first time you visit, Dify will present an initialization screen where you set the admin email, username, and password. Complete this step to create your administrator account.
Customizing Your Deployment
The .env file in the dify/docker directory is the single source of truth for configuration. Here are the most important settings you should review and potentially modify.
Changing the Exposed Port
By default, Nginx listens on port 80. If you already have a service using that port, change it:
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
After any .env change, restart the affected services:
| 1 | |
| 2 | |
Configuring the Vector Database
Dify defaults to Weaviate, but also supports Milvus, Qdrant, PgVector, OpenSearch, and others. To switch vector stores, modify the VECTOR_STORE variable in .env:
| 1 | |
| 2 | |
Each vector store has its own set of configuration variables (connection strings, API keys, etc.) documented in the .env.example file with inline comments.
Enabling File Upload Limits
Adjust the maximum file upload size for documents and images:
| 1 | |
| 2 | |
SMTP Email Configuration (Optional)
If you want features like email invitation for team members, configure SMTP:
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
Connecting Your First LLM Provider
Once Dify is running, the first thing you need to do is connect a language model. Navigate to Settings → Model Providers in the top-right corner menu.
Option A: Cloud Provider (OpenAI Example)
- Click OpenAI (or your preferred provider) from the list.
- Click Add Model or enter your API key directly.
- Paste your API key and save.
- Dify will validate the key and list available models (GPT-4o, GPT-4o-mini, etc.).
Option B: Local Model With Ollama
Running models locally eliminates API costs and keeps data entirely on your machine. First, set up Ollama:
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
Then in Dify:
- Go to Settings → Model Providers.
- Find Ollama in the list and click it.
- Enter the base URL. Since Dify runs in Docker, use the host's IP address rather than
localhost:code1 http://host.docker.internal:11434
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
You are an expert technical writer. Your job is to help users improve their technical documentation. Follow these rules:
- Always use clear, concise language.
- Prefer active voice over passive voice.
- Suggest specific improvements rather than vague feedback.
- When rewriting text, explain why your version is better.
- If the user's text contains technical inaccuracies, point them out politely.
Begin by asking the user to paste the text they want help with.
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
The target audience for this documentation is: {{audience}}.
Adjust your language complexity and examples accordingly.
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
Working With Knowledge Bases (RAG)
One of Dify's most powerful features is its built-in Retrieval-Augmented Generation (RAG) pipeline. You can upload documents, and Dify will automatically chunk, embed, and index them so your applications can search and cite the content.
Creating a Knowledge Base
- Navigate to Knowledge in the top navigation bar.
- Click Create Knowledge.
- Name it (e.g., "Company FAQ").
- Upload your documents. Dify supports TXT, Markdown, PDF, DOCX, HTML, CSV, and more.
Configuring Indexing Settings
After uploading, Dify asks you to configure how documents should be processed:
- Chunking strategy: Automatic (recommended for beginners) or custom. Custom chunking lets you set a specific character count and overlap.
- Embedding model: Choose from any embedding model available through your configured providers. A good default is
text-embedding-3-smallfrom OpenAI or a local embedding model via Ollama. - Retrieval mode: Vector search (semantic), full-text search (keyword), or hybrid (both).
Connecting the Knowledge Base to Your Application
- Open your chatbot's orchestrate page.
- In the Context section, click Add.
- Select your knowledge base.
- Save and publish.
Now when users ask questions, the chatbot will first search the knowledge base for relevant chunks, include them as context in the prompt, and generate an answer grounded in your documents.
Best Practices for Knowledge Bases
- Clean your data: Garbage in, garbage out. Remove boilerplate text, headers/footers, and irrelevant sections before uploading.
- Use appropriate chunk sizes: 500-1000 tokens with 50-100 token overlap is a good starting point for most document types.
- Test retrieval quality: Use the Hit Testing feature in the knowledge base detail page to verify that queries return relevant chunks.
- Consider hybrid retrieval: Semantic search alone can miss exact keyword matches. Hybrid search combines both approaches for better accuracy.
Building Workflows for Complex Tasks
While chatbots handle conversational interactions, Workflows enable you to build deterministic, multi-step processing pipelines. Workflows are ideal for tasks like content generation, data transformation, or multi-source research.
Understanding the Workflow Canvas
When you create a Workflow application, you are presented with a visual canvas with these key node types:
- Start — Entry point that defines input variables.
- LLM — Calls a language model with a custom prompt.
- Knowledge Retrieval — Searches a knowledge base.
- Code — Executes Python or JavaScript code.
- HTTP Request — Calls an external API.
- Conditional Branch — Routes based on conditions (if/else logic).
- Iteration — Loops over a list of items.
- Template — Formats output using Jinja2 templates.
- End — Defines the final output.
Practical Example: Automated Article Summarizer
Let us build a workflow that takes a long article URL, fetches its content, summarizes it, and translates the summary into a target language.
Step 1 — Start Node
Define two input variables:
url(string): The article URL.target_language(string): The desired output language (default: "English").
Step 2 — HTTP Request Node
Configure it to fetch the article:
- Method: GET
- URL:
{{url}} - Extract the response body text.
Step 3 — LLM Node (Summarization)
Prompt:
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
Step 4 — LLM Node (Translation)
Prompt:
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
Step 5 — End Node
Output the translated summary.
This simple workflow demonstrates how multiple nodes chain together to create a repeatable, reliable process. Each run produces consistent output regardless of how many times you execute it.
Advanced Features
MCP (Model Context Protocol) Integration
Dify supports the Model Context Protocol, an open standard that allows AI applications to securely connect with external tools and data sources. With MCP, your Dify applications can:
- Browse the web in real time
- Access databases and run SQL queries
- Interact with file systems
- Call any REST API through standardized tool definitions
To configure an MCP tool:
- Navigate to Settings → Tools or the Tools section in your workspace.
- Find the MCP-compatible tool you want to add.
- Enter the MCP server URL and any required authentication credentials.
- The tool becomes available in both chatbot and workflow applications.
Agents With Tool-Use
Agent applications give the LLM autonomy to decide which tools to use and in what order. Unlike workflows (which have a fixed execution path), agents dynamically plan their actions based on the user's request.
To create an Agent:
- Create a new application and select Agent type.
- Configure the system prompt and available tools.
- Choose the reasoning strategy: Function Calling (for models that support it) or ReAct (for others).
Agents are powerful but less predictable than workflows. Use agents for open-ended tasks and workflows for well-defined processes.
Text-to-SQL and Data Analysis
Dify can connect directly to databases and allow natural language querying. The workflow is:
- Connect a database (MySQL, PostgreSQL, etc.) through the tools configuration.
- The LLM translates the user's natural language question into a SQL query.
- The query executes against your database.
- Results are returned to the LLM, which formats them as a human-readable answer or even generates an ECharts visualization.
This pattern is particularly valuable for internal analytics tools where non-technical team members need to query data.
Troubleshooting Common Issues
Containers Fail to Start
Symptom: One or more containers show Exited status.
Solution: Check logs with docker compose logs <service_name>. The most common causes are:
- Port conflicts (another service using port 80 or 443). Change
EXPOSE_NGINX_PORTin.env. - Insufficient memory. Increase Docker's memory limit in Docker Desktop settings.
- Corrupted
.envfile. Verify the syntax has no trailing spaces or missing quotes.
Knowledge Base Indexing Stuck at 0%
Symptom: Documents upload successfully but indexing never completes.
Solution: This usually indicates the embedding model is not configured or the Worker service is not running:
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
Cannot Connect to Ollama From Docker
Symptom: Dify shows connection errors when trying to reach Ollama.
Solution: Docker containers cannot reach localhost on the host machine. Use:
- macOS/Windows:
http://host.docker.internal:11434 - Linux: Add
extra_hosts: ["host.docker.internal:host-gateway"]to thedocker-compose.yamlunder the API and Worker services, or use the host's actual IP address.
Slow Performance
Symptom: The interface is sluggish, and responses take a long time.
Solutions:
- Allocate more RAM to Docker (at least 8 GiB).
- Use a faster LLM (GPT-4o-mini instead of GPT-4, or a smaller local model).
- If using Weaviate with large datasets, consider switching to a dedicated vector database server.
Updating Dify to a New Version
To update your local Dify deployment to the latest release:
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
Important: Always back up your PostgreSQL data before major updates. Use
docker compose exec db_postgres pg_dump -U postgres dify > backup.sqlto create a backup.
Recommended Learning Path
Based on the comprehensive Dify learning curriculum from the community, here is a progressive path to master the platform:
Beginner (Week 1)
- Complete local deployment (this guide).
- Build a simple chatbot with prompt engineering.
- Experiment with different LLM providers and compare outputs.
Intermediate (Weeks 2-3) 4. Create a knowledge base application with RAG. 5. Build a multi-step workflow for a content generation pipeline. 6. Set up an Agent with external tool access.
Advanced (Weeks 4+) 7. Implement Text-to-SQL for database querying. 8. Configure MCP tools for real-time web access. 9. Build a Deep Research agent that autonomously investigates complex topics. 10. Explore multi-modal capabilities (voice-to-text, image generation).
Conclusion
Deploying Dify locally gives you a powerful, private AI application development platform without recurring cloud costs or data privacy concerns. The Docker Compose deployment makes it accessible even to those without deep DevOps experience — a single docker compose up -d command brings up a complete production-grade stack.
The real value of Dify lies not just in its deployment simplicity, but in the breadth of capabilities it unlocks: visual workflow orchestration, RAG-powered knowledge bases, autonomous agents, database integrations, and MCP tool connectivity. Start with a simple chatbot, iterate toward more complex workflows, and gradually incorporate advanced features as your understanding deepens.
For further exploration, consult the official documentation at docs.dify.ai, join the community forum at forum.dify.ai, and follow the releases at github.com/langgenius/dify to stay current with new features and improvements.