Dify Local Deployment in Practice: A Complete Guide to Building an AI Application Platform with Docker

A step-by-step guide to deploying Dify locally with Docker to build a private AI application platform.
This article walks through the full process of deploying Dify locally with Docker—from installing Docker and Docker Compose, pulling the source code and preparing the config file, to starting containers and first access. It also covers connecting a local LLM via Ollama, forming a complete private AI development stack for enterprise use.
Why Choose Dify for AI Application Development
In the field of large language model application development, Dify has become one of the most frequently used tools for building enterprise-grade AI applications. It complements code-development tools (such as Cursor) and together they form a critical part of the modern AI development infrastructure.
Dify is an open-source LLM application development platform built on a RAG (Retrieval-Augmented Generation) engine. RAG is currently the core architectural paradigm for deploying enterprise AI applications—its essence is decoupling parametric knowledge (knowledge frozen in model weights up to the training cutoff date) from non-parametric knowledge (an enterprise's own, real-time updatable external knowledge base). When a user asks a question, the system first retrieves the text fragments most relevant to the question from the external knowledge base, then splices those fragments into the prompt as context and sends everything to the LLM to generate an answer. This mechanism effectively addresses the LLM's knowledge cutoff and hallucination problems, while avoiding full fine-tuning costs that can run into hundreds of thousands of dollars—enterprises only need to maintain and update their knowledge base documents to keep the model up to date on the latest business knowledge.
The retrieval stage is typically implemented using a vector database (such as Milvus, Weaviate, Qdrant, etc.). The core working principle of a vector database is: an embedding model chunks documents and converts them into high-dimensional dense vectors (typically 768 to 4096 dimensions), builds an approximate nearest neighbor (ANN) index structure in the database (such as HNSW, IVF, etc.), and at query time vectorizes the user's question in the same way, then performs sub-second semantic retrieval across billions of vectors via cosine similarity or dot product operations. Unlike traditional keyword-based retrieval, vector retrieval can capture semantic-level similarity—even when different words are used, semantically similar content can still be precisely recalled. Dify encapsulates the complex stages of the RAG pipeline—document parsing, vectorization, index building, retrieval recall, and more—into visual operations, so users only need to upload documents to build an enterprise-specific knowledge base.
Dify supports unified access to dozens of model APIs, including OpenAI, Anthropic, and major domestic large models. Its underlying tech stack uses a Python/Flask backend and a React frontend, and the whole thing is distributed as Docker containers to ensure a consistent experience across different operating systems. Dify was born in 2023 and quickly accumulated a large number of GitHub Stars, becoming one of the benchmark open-source projects in the LLMOps (large model operations) space.
LLMOps (Large Language Model Operations) is an emerging concept that evolved from MLOps, specifically targeting the full lifecycle management of large model applications. Traditional MLOps focuses on data pipelines, model training, feature engineering, and A/B testing; LLMOps additionally focuses on large-model-specific concerns such as prompt version management (minor wording changes in a prompt can cause large fluctuations in output quality, so prompts require version control and regression testing just like code), token cost monitoring (API call costs are directly tied to context length, requiring fine-grained cost attribution and budget control), output content safety filtering (guardrails, to prevent the model from producing harmful, non-compliant, or inappropriate content), and multi-model routing strategies (dynamically selecting the most suitable model based on task complexity, cost, and latency). As an LLMOps platform, Dify provides capabilities such as conversation log tracing, a prompt debugging sandbox, side-by-side multi-model comparison, and application version release management, helping teams bring the development, testing, launch, and iteration of AI applications into a manageable engineering system.
Dify's most core value lies in its low-code/no-code development capabilities—you can quickly build chatbots and agents without writing large amounts of code, and orchestrate business workflows through a visual interface. The core of an agent is granting the model a "plan—tool call—observe feedback" loop capability: the typical ReAct (Reasoning + Acting) architecture lets the model autonomously decide during its response whether to call external tools (such as search engines, code executors, database query interfaces), and continue reasoning based on the tool's returned results until the task is complete. Dify's workflow orchestration allows developers to define multi-step business processes as a directed acyclic graph (DAG), chaining together components such as LLM nodes, code nodes, conditional branches, HTTP requests, and knowledge base retrieval into reusable automation pipelines, making complex business logic—such as contract review, report generation, and multi-turn customer service routing—achievable without writing code by hand.
Low-code/no-code platforms lower the development barrier through visual drag-and-drop and prebuilt components. In the AI field, they further abstract away complex underlying logic such as prompt engineering, model invocation, context management, and memory storage, enabling non-technical roles such as product managers and business analysts to directly participate in building and iterating on AI applications, dramatically shortening the cycle from idea to launch.
This article focuses on the installation and local deployment of Dify, helping you build a controllable and efficient private AI application development environment.
Online Experience vs. Local Deployment: How to Choose
Dify offers two main ways to use it, each with its own applicable scenarios.
Limitations of the Online Approach
After visiting the Dify official website and clicking "Get Started," you can open the online workspace without any installation—ideal for quick experimentation. However, the online approach has two obvious shortcomings:
- Restricted network access: Response speeds are slow in domestic (China) network environments, affecting the smoothness of operation.
- Reliance on external model services: Poor data controllability, unsuitable for enterprise scenarios with data security requirements.

Core Advantages of Local Deployment
Local deployment can completely eliminate network limitations, and combined with a local large model, it achieves higher development efficiency and data security. For enterprise-grade applications, Dify private deployment is the more recommended approach.
On-premises deployment means fully deploying the software system on the enterprise's own or controllable infrastructure, with all data flows completed within the internal network without passing through any third-party cloud servers. For highly regulated industries such as finance, healthcare, and government, private deployment is a necessary prerequisite for meeting data security regulatory requirements (such as China's Data Security Law and Personal Information Protection Law, MLPS 2.0, the EU's GDPR, etc.). It's worth noting that private deployment isn't a consideration only for large enterprises—even for small and medium-sized enterprises, when an AI system needs to handle sensitive information such as customer contracts, employee records, and financial data, keeping data within a self-controlled environment is likewise the most direct way to reduce compliance and leakage risks. Even for ordinary enterprises, keeping sensitive information such as internal knowledge bases and customer data within a self-controlled environment is the most direct way to reduce the risk of data leakage.
Environment Preparation: Installing Docker and Docker Compose
Dify local deployment is based on Docker container technology, and Docker and Docker Compose are essential prerequisites.
Docker is currently the most mainstream containerization platform in the industry. Its core idea is "build once, run anywhere"—by packaging an application and all its dependencies into a standardized image, it ensures the application behaves identically in any Docker-supported environment. Docker's isolation capabilities come from two core Linux kernel technologies: namespaces and cgroups. Namespaces provide each container with an isolated view, including the process tree (PID namespace), network stack (Network namespace), filesystem mount points (Mount namespace), and hostname (UTS namespace), making processes inside a container believe they have the entire operating system to themselves. Cgroups (Control Groups) impose limits at the resource level, precisely controlling how much CPU time slice, memory ceiling, and disk I/O bandwidth each container can use, preventing a single container from exhausting host resources. Docker images use a layered storage structure based on a union filesystem (UnionFS)—each Dockerfile instruction generates a read-only layer, and at runtime the container stacks a writable layer on top, allowing images to efficiently share base layers and be distributed quickly.
These underlying mechanisms have direct engineering significance in the actual deployment of Dify: understanding the Network namespace helps troubleshoot service discovery issues between containers (for example, why the Dify container cannot access the Ollama service on the host via localhost); understanding cgroup limits helps sensibly adjust resource quotas for each component when memory is tight; and understanding image layering explains why the first image pull takes longer while subsequent updates are much faster.
Docker Compose is the companion multi-container orchestration tool. At runtime, Dify needs to simultaneously start multiple components such as the web service, API service, database, vector database, and message queue—Dify has built-in support for vector databases such as Weaviate, Qdrant, Milvus, and PGVector by default, and uses Weaviate as the default vector storage backend, started together with docker compose. Docker Compose uses a single YAML configuration file (docker-compose.yaml) to uniformly define the dependencies, network configuration, and startup order of these services, so the entire complex system can be started and stopped with just one command. If you plan to handle millions of documents in a production environment, it's recommended to evaluate a more horizontally scalable vector database solution such as Milvus.
Minimum System Requirements
According to the Dify official GitHub repository documentation, the runtime environment must meet:
- CPU: No fewer than 2 cores
- RAM: No less than 4GB
The core startup command is just one line, docker compose up -d, but the prerequisite is that your machine already has a complete Docker Compose environment.
Installation on Linux (Ubuntu / CentOS)
The installation process is basically the same for both distributions:
- Install Docker: Use the official installation script, which automatically handles the installation of Docker and related dependencies.
- Install Docker Compose: After completion, run
docker-compose --version; if it outputs the version number normally, installation was successful.
Tip: Image pull speeds are slow in domestic (China) network environments, so it's recommended to configure an image acceleration proxy in advance—this step is almost mandatory optimization. Available Docker image acceleration services in China include Alibaba Cloud Container Registry, Tencent Cloud image accelerator, etc. The configuration method is to modify Docker's
daemon.jsonfile, adding aregistry-mirrorsfield pointing to the acceleration address. After configuration, you need to restart the Docker daemon (systemctl restart docker) for the changes to take effect.

Installation on Windows and Mac
Windows users are recommended to use Docker Desktop directly: download the .exe installer from the Docker official website and double-click to install. On Windows, Docker Desktop runs on WSL 2 (Windows Subsystem for Linux 2) or Hyper-V virtualization technology, seamlessly integrating the Linux container environment into the Windows system, while also providing a graphical interface for conveniently managing container states, viewing logs, and monitoring resource usage.
It's worth mentioning that WSL 2 differs fundamentally from the earlier WSL 1: WSL 1 achieves Linux compatibility through system call translation, whereas WSL 2 runs a full Linux kernel (in a lightweight Hyper-V virtual machine), so Docker containers can directly use real Linux cgroup and namespace mechanisms, greatly improving performance and compatibility. This is also why Microsoft has continued to invest in WSL 2 in recent years—it makes Windows a truly developer-friendly cross-platform environment.
The steps for Mac users are similar. After Docker Desktop is installed, the built-in terminal can execute the subsequent commands, or you can use the system's built-in command-line tools.

Dify Local Deployment Startup Process
Once the environment is ready, the process of starting Dify is fairly straightforward, divided into the following steps.
Step 1: Get the Source Code and Prepare the Configuration File
Pull the Dify source code from GitHub, extract it, and enter the docker folder in the source directory—this is the key location for executing the startup command, where the Docker Compose configuration file is located.
The pitfall beginners most easily fall into: There is a .env.example file in the directory, which must be manually renamed to .env (removing the .example suffix), otherwise the configuration will not take effect. The .env file is a standard convention for storing environment variables in Unix/Linux systems. When starting up, Docker Compose automatically reads the .env file in the same directory and injects the variables defined in it (such as database passwords, port numbers, keys, etc.) into the container's runtime environment. Open-source projects typically only provide .env.example as a template example, to avoid accidentally committing a configuration file containing real keys to the code repository—this is a common industry security practice (usually paired with .gitignore to exclude the .env file from version control), and it's also the most common issue in Dify deployment, so be sure to note it in advance.
For a production deployment, it's recommended to focus on checking several key configuration items in the .env file: SECRET_KEY (used for session encryption, which should be replaced with a randomly generated strong key), the database default password (which should be changed to a complex password), and NGINX_HTTPS_ENABLED (enabling HTTPS is recommended in production).
Step 2: Execute the Startup Command
In the docker directory, execute:
docker compose up -d
The -d parameter means running in daemon (background) mode; the containers will start all related components in the background, with no logs output to the foreground. A daemon is a process that runs continuously in the background without interacting with the user terminal, suitable for service-type applications that need to reside long-term. Removing the -d parameter runs in foreground mode, where you can see all container log output in real time—suitable for the debugging and troubleshooting phase; after closing the terminal or pressing Ctrl+C, all containers stop. If you need to run in the background while also viewing logs, you can use the docker compose logs -f command to continuously follow the output.
Note: The first execution needs to pull multiple images, which takes a while, so please be patient. In domestic environments, be sure to configure image acceleration in advance.

First Access and Administrator Account Setup
Dify listens on port 80 by default. After the containers finish starting, access the following address in your browser to enter the initialization interface:
http://localhost/install
Steps for first access:
- Switch the language: Set the interface language to Simplified Chinese.
- Create an administrator account: Fill in the administrator email, username, and login password.
- Log in to the system: After setup, you'll be redirected to the login page; enter the account and password you just created to log in.
After logging in successfully, you officially enter the Dify workspace, where you can start creating chatbots, agents, or workflow applications.
Next Step: Connecting a Local Large Model
Completing Dify local deployment is just the first step. To build a truly usable AI application, you also need to configure an inference model or embedding model for it.
Since you've already deployed Dify privately, the ideal approach is to also deploy a large model locally (for example via tools like Ollama), forming a complete private AI development loop. Ollama is currently one of the most popular local large model runtime frameworks. It's built on llama.cpp—a highly efficient inference engine implemented in pure C/C++ that supports CPU inference and GPU acceleration (CUDA/Metal). The GGUF (GPT-Generated Unified Format) quantization format introduced by llama.cpp is a key technical breakthrough for local model deployment: it compresses model weights from the standard FP32 (4 bytes per parameter) or FP16 (2 bytes per parameter) to 4-bit quantization formats such as Q4_K_M (about 0.5 bytes per parameter), reducing model size to 1/8 to 1/4 of the original within an acceptable range of precision loss. This makes it possible to run a 7-billion-parameter model that would originally require a professional GPU server (for example, the FP16 version of Llama 3 8B needs about 16GB of VRAM) at practical speeds on consumer-grade graphics cards (such as the RTX 3060 12GB) or even in a pure CPU environment.
On top of llama.cpp, Ollama further encapsulates model management (similar to Docker's image mechanism, downloading models via the ollama pull command), multi-concurrency scheduling, and a REST API service. It supports one-click download and running of dozens of mainstream open-source models such as Llama 3, Qwen 2.5, Mistral, and Gemma, and exposes a local endpoint fully compatible with the OpenAI REST interface specification (default is http://localhost:11434), which means almost all client code designed for OpenAI can switch to a local model with virtually no modification.
In Dify's model provider settings, select "Ollama" and fill in the corresponding address to connect—note that in a docker-compose environment, the Dify container cannot access host services via localhost, so you usually need to fill in the address as http://host.docker.internal:11434 (applicable to Windows/Mac); on Linux, you typically use the host's actual IP address or the Docker bridge IP (such as http://172.17.0.1:11434). For the embedding model, you can choose an embedding model such as nomic-embed-text provided by Ollama, which provides text vectorization support for RAG scenarios such as knowledge base Q&A. This "Dify + Ollama" combination both guarantees data security and completely eliminates reliance on online services, making it the optimal practice for local AI development. Connecting a local model will be a key part of building enterprise-grade AI applications later on.
Summary
The core process of Dify local deployment can be summarized in three steps: Configure the Docker environment → Pull the source code and prepare the configuration file → Start the containers and access the workspace. Each stage has a clear operational path, and you can complete it by following the steps.
Once you've mastered local deployment, you've laid a solid foundation for subsequently building chatbots, agents, and complex business workflows. For enterprise developers, the combination of Dify private deployment + local large model is truly the optimal solution for achieving controllable AI application deployment—Dify provides visual application orchestration and LLMOps management capabilities, Ollama provides a secure and efficient local inference runtime, and the vector database carries the enterprise's knowledge assets. Together, the three form a complete private AI development infrastructure: Dify handles orchestration and governance at the application layer, Ollama handles inference and management at the model layer, and the vector database handles storage and retrieval at the knowledge layer—forming a three-tier architecture with clear responsibilities that can each scale independently. This is a solid starting point for enterprises to build long-term, maintainable AI capabilities.
Key Takeaways
Related articles

Should You Open Source Your Project? A Layered Open Source Strategy Using Project Replay as a Case Study
Should indie developers open source their projects? Using the game custom achievement tool Project Replay as a case study, this article analyzes the open source decision and offers a practical layered strategy.

130+ Open-Source Interactive Security Awareness Training: Reshaping Habit Formation Through 3D Office Scenarios
A project with 130+ free open-source interactive security awareness exercises using immersive 3D office scenarios to simulate phishing, vishing, MFA fatigue attacks and more, building employee security habits.

From Musk to Jefferson: Beware the Cognitive Trap of Cross-Domain Experts
Why do geniuses in one field often become overconfident in others? From Musk's controversial interview to Jefferson's blind spots, an exploration of cross-domain cognitive arrogance.