Docker Deployment and Upgrades#
Dify's primary self-hosted deployment is a Docker Compose stack under the docker/ directory. The stack file docker/docker-compose.yaml is auto-generated from docker/docker-compose-template.yaml โ never edit it directly. Operator customization goes into docker/.env or the matching optional service .env file under docker/envs/. The root file is copied from docker/.env.example.
As of v1.18.0, the stack runs seven core application services (api, api_websocket, worker, worker_beat, web, plugin_daemon, agent_backend) plus supporting infrastructure (db_postgres, redis, nginx, ssrf_proxy, agent_ssrf_proxy, sandbox, local_sandbox, init_permissions). Optional vector store backends and the workflow collaboration service are activated via the COMPOSE_PROFILES variable in .env.
Minimum requirements: CPU โฅ 2 cores, RAM โฅ 4 GiB, Docker โฅ 19.03, Docker Compose โฅ 2.35.0, and OpenSSL for token generation.
Initial Deployment#
git clone --branch <TAG> https://github.com/langgenius/dify.git
cd dify/docker
cp .env.example .env
openssl rand -hex 32
# Paste the generated value into DIFY_AGENT_LOCAL_SANDBOX_AUTH_TOKEN in .env.
docker compose up -d
Navigate to http://localhost/install to complete setup. See the official quick-start guide for full details.
Pre-built images are used by default โ no source code is volume-mounted, so code changes require a rebuild. Choose a vector store by setting VECTOR_STORE in root .env (e.g., weaviate, milvus, opensearch) and including the matching profile in COMPOSE_PROFILES. Compose automatically loads envs/vectorstores/<VECTOR_STORE>.defaults for the API, workers, and Beat. To customize the connection, copy the provider's .defaults file to its .env path or edit the existing override; both Elasticsearch selectors use elasticsearch.env. For an external store, omit its bundled profile and supply its connection settings and credentials.
Changing VECTOR_STORE selects the default for new indexes; existing knowledge bases retain their stored backend. Keep that backend's service running and preserve its connection settings. Bundled Weaviate defaults remain available when another provider is selected, but retain the weaviate profile if existing knowledge bases use it. Changing providers does not migrate data.
With VECTOR_STORE=opensearch, OPENSEARCH_VERIFY_CERTS defaults to true, including for external connections without the bundled profile. Use trusted certificates in production. For local development with bundled demo certificates, explicitly set OPENSEARCH_VERIFY_CERTS=false in envs/vectorstores/opensearch.env or root .env. Saved false overrides remain in effect after upgrades; remove them or set true to enable verification. See Select a database or vector store.
Environment Variable Management#
For services that load root docker/.env, effective precedence is (highest first):
docker/.envโ explicit deployment overrides.docker/envs/**/*.envโ optional per-service overrides (seedocker/envs/).- Tracked
docker/envs/**/*.defaultsvalues, then application defaults for unset settings.
Services that do not load root .env, including databases, vector stores, and nginx, receive root values only through ${...} expressions in defaults or explicit Compose mappings. Arbitrary native container variables must go in the matching service override file; for example, set Weaviate's ASYNC_INDEXING in envs/vectorstores/weaviate.env, not root .env alone. The knowledge_fs_unstructured parser loads its defaults and envs/core-services/knowledge-fs-unstructured.env without root .env; set its parsing options in that service file.
Shell values take precedence during Compose interpolation; explicit Compose environment: entries override env-file values. Docker Compose v2.35.0 or later is required for root overrides to take precedence when resolving service defaults. See the Docker configuration guide.
docker/.env.example is the minimal template for required deployment inputs. Review it and the matching .defaults files after every upgrade; preserve existing local .env files. To customize a service, copy its .defaults file to the documented .env path, edit input settings, and leave container-variable mapping expressions unchanged. Service override paths other than the retired envs/core-services/shared.env remain valid. Apply changes with docker compose up -d; docker compose restart does not reload environment variables.
Configure public console and app URLs in envs/core-services/urls.env, shared by web, API, and workers, including Beat and KnowledgeFS workers. Copy urls.defaults only if urls.env does not exist; otherwise edit it in place. Set CONSOLE_API_URL, CONSOLE_WEB_URL, SERVICE_API_URL, APP_API_URL, and APP_WEB_URL to public base URLs without /console/api, /api, or /v1 suffixes. Empty values use the current origin and explicitly clear image-level localhost defaults. CONSOLE_API_URL serves both browser requests and API-generated links such as plugin icons. Explicit urls.env values override URL settings in individual service files; root .env overrides both. Existing service URL overrides remain effective when urls.env is absent or copied unchanged. Web's internal SERVER_CONSOLE_API_URL remains independently configurable in web.env, defaulting to http://api:5001.
Before recreating containers, migrate any envs/core-services/shared.env settings; the file is not loaded by any service:
- Back up
shared.env,api-worker.env, andurls.envif present. - From
docker/, renameenvs/core-services/shared.envtoenvs/core-services/api-worker.envonly if the latter does not exist. If both exist, merge only missing settings intoapi-worker.env, keeping its existing values for duplicate keys, including intentional empty values. Do not overwrite an existing override with a defaults template. - Move intended public URL values to
urls.envand remove duplicate URL assignments from individual service files. Root.envURL values can remain and retain precedence. Keep internalSERVER_CONSOLE_API_URLoverrides inweb.env. - Archive or remove any remaining
shared.envafter preserving its settings, then rundocker compose up -dwith the deployment's existing Compose project/options. Leavingshared.envin place has no effect. Deployments without this file need no legacy-file migration.
See the Docker configuration and migration guide.
The optional dify-env-sync.sh script backs up root .env to env-backup/, adds missing keys from root .env.example, and preserves existing values and extra overrides. It does not synchronize the files under envs/.
Key variables to verify on every deployment or upgrade:
| Variable | Notes |
|---|---|
SECRET_KEY | Leave empty to let Dify generate a persistent key stored in backend storage and reused across containers. Set explicitly for production if you prefer manual control; the same value must be used for both api and api_websocket |
COMPOSE_PROFILES | Controls vector stores, database type, and collaboration service. Default: weaviate,postgresql,collaboration |
PLUGIN_DAEMON_KEY | Shared secret for API โ plugin daemon; rotate from default in production |
PLUGIN_DAEMON_URL | Must use Docker service name: http://plugin_daemon:5002 โ not localhost |
DB_TYPE | Required since 1.15.0; set to postgresql when upgrading from older versions |
DIFY_AGENT_LOCAL_SANDBOX_AUTH_TOKEN | Required nonblank secret for the Local sandbox. Set it only in root docker/.env; Compose supplies it to both agent_backend and local_sandbox. Move any existing copy from envs/core-services/dify-agent.env to root .env and remove the duplicate, keeping the same secret |
The local_sandbox service starts shellctl serve with --require-auth-token, so a missing, empty, or whitespace-only token makes it exit before initialization. Compose's explicit environment values override the service env file, including with an empty interpolated value, which is why the token belongs in root docker/.env. The runtime image must support this flag: when upgrading, pull or rebuild the local_sandbox image (docker compose pull, or rebuild from dify-agent-runtime/ for a custom image). Historical note: the earlier langgenius/dify-agent-local-sandbox:1.17.1 image does not support --require-auth-token; the Compose stack at 1.18.0 references langgenius/dify-agent-local-sandbox:1.18.0 (and 1.18.0 tags for the api, web, worker, and agent_backend images), which does.
Standard Upgrade Procedure#
Before recreating containers, complete the shared.env migration described under Environment Variable Management if that file exists. The canonical sequence for any version bump :
cd docker
git pull
docker compose pull
docker compose up -d
Then run these post-start commands in order:
-
Apply schema migrations (auto-runs on startup when
MIGRATION_ENABLED=true; run explicitly to confirm):docker compose exec api flask upgrade-dbImplementation:
api/commands/system.py -
Backfill plugin auto-upgrade strategies โ mandatory after 1.15.0+; must run after
upgrade-dbbecause it depends on thecategorycolumn added by that migration :docker compose exec api flask backfill-plugin-auto-upgradeImplementation:
api/commands/plugin.pyAutomatic plugin upgrade checks are deduplicated by tenant, plugin category, and scheduled UTC day, with at most 20 child checks executing across workers sharing a Redis deployment namespace. Before relying on this bound, verify that every consumer of the
pluginqueue runs the coordinated task implementation and shares the same namespaced Redis state; older workers bypass the bound. When moving from the 24-hour to the three-hour queue deadline, upgrade all workers that consume thepluginqueue together. Both scheduling and execution use this queue. A worker using the 24-hour policy can skip a pending reservation with a three-hour deadline or reissue a check if it replays the original scheduling task after the marker expires. Use a worker pool that enforces the 30-minute task hard limit (prefork or cooperative gevent). Active coordination keys must not be evicted. A newly scheduled check must start within three hours of its original scheduling timestamp. Broker expiration and admission retries use the same deadline; checks that start in time keep their existing execution lease. This does not restrict the configured upgrade time within the UTC day. In-flight reservations and published checks keep their original deadlines. Size and monitor Redis memory for the daily tenant/category strategy cardinality. Completed reservations retain onlystate=donein their Redis hash and expire at the original queue deadline, even if the execution lease extended the key's lifetime. Seeapi/tasks/plugin_autoupgrade_coordination.pyandapi/tasks/process_tenant_plugin_autoupgrade_check_task.py. -
Verify plugin daemon image tag matches the Dify release โ see Plugin Daemon Synchronization below.
-
Clean stale plugin directories โ remove subdirectories in
./volumes/plugin_daemon/plugin/that logrecord not foundin the daemon, after confirming plugins work in the UI.
Version-Specific Breaking Changes#
Standard docker compose up + flask upgrade-db is not sufficient for the following upgrades. The full catalog lives in the Release Breaking Changes KB.
1.9.0 โ Datasource Credential Migration#
After upgrading, run :
docker compose exec api flask transform-datasource-credentials
โ ๏ธ Users on v2.0.0-beta.1/beta.2 face a destructive migration. Back up your database first.
1.13.0 โ New Celery Queue#
A new workflow_based_app_execution Celery queue was added for Human-in-the-Loop workflows. If you use a custom CELERY_QUEUES, add workflow_based_app_execution explicitly. New PubSub env vars (PUBSUB_REDIS_URL, PUBSUB_REDIS_CHANNEL_TYPE) were also introduced.
1.14.x โ model_type Enum Rename and Duplicate Plugin Identifier#
Enum rename: Three model_type values were renamed without an automatic data migration :
| Old value | New value |
|---|---|
text-generation | llm |
embeddings | text-embedding |
reranking | rerank |
Symptom: UI shows "Credentials unavailable"; HTTP 400 "Credential with id โฆ not found". Inference still works; management operations are broken.
Fix (CLI, recommended):
docker compose exec api flask data-migrate legacy-model-types # dry-run first
docker compose exec api flask data-migrate legacy-model-types --apply
From Alembic migration 2026_08_27_1200-5578e028b2f2 (PR #41326) onward, flask upgrade-db applies this automatically.
Implementation: api/commands/data_migration.py and api/services/legacy_model_type_migration.py.
Duplicate plugin_unique_identifier: Upgrading from 1.13.x may cause the daemon to restart in a loop (SQLSTATE 23505) due to a unique index creation failure. Deduplicate rows in dify_plugin.plugins (keep the most recent), then restart the daemon. See Issue #38276.
1.15.0 โ Multiple Breaking Changes#
-
DB_TYPEnow required โ addDB_TYPE=postgresqlto.env. -
SSRF proxy deny-by-default โ blocks all RFC-1918 private IPs and all destinations except
.marketplace.dify.ai. Workflow HTTP-request nodes calling internal endpoints return403 Forbidden. Fix by adding to.envand restarting the proxy :SSRF_PROXY_ALLOW_PRIVATE_DOMAINS=internal.mycompany.com,ollama SSRF_PROXY_ALLOW_PRIVATE_IPS=10.10.5.42,192.168.1.0/24docker compose restart ssrf_proxyConfig template:
docker/ssrf_proxy/squid.conf.template. The entrypointdocker/ssrf_proxy/docker-entrypoint.shinjects these as Squid ACL fragments at startup. -
Legacy model type migration โ
flask upgrade-dbalone is not sufficient for pre-1.15.0 databases; also runflask data-migrate legacy-model-types --apply. -
Plugin backfill โ
flask backfill-plugin-auto-upgradeis now mandatory after every upgrade.
1.17.0 โ EDITION Removed, Timeout Defaults Changed#
Before starting services, update .env :
- Remove
EDITIONandENTERPRISE_ENABLED; useDEPLOYMENT_EDITIONinstead. - Remove
AGENT_BACKEND_RUN_TIMEOUT_SECONDSandDIFY_AGENT_SHELLCTL_*variables. - Note:
APP_MAX_EXECUTION_TIMEandWORKFLOW_MAX_EXECUTION_TIMEdefaults changed from 1200 s โ 3600 s.
The model type migration (from 1.14.x) is still required if upgrading from any version earlier than 1.15.0 that has not yet applied it โ it is not included in flask db upgrade.
Plugin Daemon Synchronization#
The plugin daemon (langgenius/dify-plugin-daemon) is a separate Go-based service that must stay in version lockstep with the Dify API. Protocol mismatches cause complete communication failure โ the daemon logs "failed to find the version of the plugin sdk" and the API returns connection errors.
| Dify API | Plugin Daemon image tag |
|---|---|
| 1.13.x | 0.5.x |
| 1.14.x | 0.6.x |
| 1.15.0โ1.17.x | 0.6.11-local (or matching release tag) |
| 1.19.0 | 0.6.14-local (Compose definition) |
| 1.20.0 | 0.6.15-local (Compose definition) |
The daemon communicates with the API at http://plugin_daemon:5002 (Docker service DNS โ never localhost) and maintains a separate PostgreSQL database (dify_plugin, configurable via DB_PLUGIN_DATABASE) that must exist before the daemon starts.
Set both PLUGIN_DAEMON_KEY and PLUGIN_DIFY_INNER_API_KEY in root docker/.env so the daemon and all clients receive matching values. Leave derived container key expressions unchanged in copied service files; changing only one service file can cause HTTP 401 responses. Two shared secrets must match on both sides :
docker/.env variable | Daemon variable | Direction |
|---|---|---|
PLUGIN_DAEMON_KEY | PLUGIN_DAEMON_KEY | API โ Daemon auth |
PLUGIN_DIFY_INNER_API_KEY | DIFY_INNER_API_KEY | Daemon โ API auth |
Plugin storage bind-mounts ./volumes/plugin_daemon โ /app/storage. Back up this directory to preserve installed plugins across host restarts.
For plugin DB integrity issues (duplicate identifiers, daemon schema init failures), see the Plugin Database Integrity KB and Plugin Daemon Architecture KB.
Key Files and References#
| Resource | Purpose |
|---|---|
docker/docker-compose.yaml | Auto-generated stack; do not edit directly |
docker/docker-compose-template.yaml | Source template for the compose file |
docker/.env.example | Minimal required-input template; copy to .env |
docker/envs/ | Tracked service defaults and optional per-service env overrides |
docker/ssrf_proxy/squid.conf.template | Full Squid ACL rules (deny-by-default since 1.15.0) |
api/commands/system.py | flask upgrade-db implementation |
api/commands/plugin.py | flask backfill-plugin-auto-upgrade implementation |
api/commands/data_migration.py | flask data-migrate legacy-model-types |
api/services/legacy_model_type_migration.py | Online migration logic for model_type enum rename |
| Official quick-start guide | Step-by-step deployment docs |
| Release Breaking Changes KB | Full per-version breaking change catalog |
| Plugin Daemon Architecture KB | Version pairings, communication protocol, troubleshooting |
| Plugin Database Integrity KB | Diagnostic queries and SQL recovery scripts |