Implementation:Langgenius Dify Web Entrypoint
| Knowledge Sources | |
|---|---|
| Domains | Frontend Docker Process Management |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
The entrypoint.sh script is the Docker container entrypoint for the Dify web frontend, responsible for mapping Docker Compose environment variables to Next.js NEXT_PUBLIC_* variables and launching the application via PM2 in cluster mode.
Description
Located at web/docker/entrypoint.sh (47 lines), this shell script bridges the gap between Docker's environment variable injection and Next.js's runtime configuration requirements. It runs as the container's entrypoint (PID 1) and performs two tasks: environment variable mapping and process launching.
Environment Variable Mappings (Lines 15-44):
The script exports approximately 30 NEXT_PUBLIC_* environment variables by reading from Docker Compose-injected variables. The mappings fall into several categories:
Core API URL Mappings (with path suffix appended):
CONSOLE_API_URLmaps toNEXT_PUBLIC_API_PREFIXwith/console/apisuffix appendedAPP_API_URLmaps toNEXT_PUBLIC_PUBLIC_API_PREFIXwith/apisuffix appendedMARKETPLACE_API_URLmaps toNEXT_PUBLIC_MARKETPLACE_API_PREFIXwith/api/v1suffix appended
Direct Mappings (one-to-one, no transformation):
DEPLOY_ENVmaps toNEXT_PUBLIC_DEPLOY_ENVEDITIONmaps toNEXT_PUBLIC_EDITIONNEXT_PUBLIC_BASE_PATHpasses through directlyMARKETPLACE_URLmaps toNEXT_PUBLIC_MARKETPLACE_URL_PREFIXNEXT_PUBLIC_COOKIE_DOMAINpasses through directlySENTRY_DSNmaps toNEXT_PUBLIC_SENTRY_DSNSITE_ABOUTmaps toNEXT_PUBLIC_SITE_ABOUTNEXT_TELEMETRY_DISABLEDpasses through directlyAMPLITUDE_API_KEYmaps toNEXT_PUBLIC_AMPLITUDE_API_KEY
Feature Flag Mappings (with defaults):
ALLOW_UNSAFE_DATA_SCHEMEmaps toNEXT_PUBLIC_ALLOW_UNSAFE_DATA_SCHEME(default:false)ENABLE_WEBSITE_JINAREADERmaps toNEXT_PUBLIC_ENABLE_WEBSITE_JINAREADER(default:true)ENABLE_WEBSITE_FIRECRAWLmaps toNEXT_PUBLIC_ENABLE_WEBSITE_FIRECRAWL(default:true)ENABLE_WEBSITE_WATERCRAWLmaps toNEXT_PUBLIC_ENABLE_WEBSITE_WATERCRAWL(default:true)NEXT_PUBLIC_ENABLE_SINGLE_DOLLAR_LATEXpasses through (default:false)
UI Configuration Mappings (no defaults):
TEXT_GENERATION_TIMEOUT_MSmaps toNEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MSCSP_WHITELISTmaps toNEXT_PUBLIC_CSP_WHITELISTALLOW_EMBEDmaps toNEXT_PUBLIC_ALLOW_EMBEDTOP_K_MAX_VALUEmaps toNEXT_PUBLIC_TOP_K_MAX_VALUEINDEXING_MAX_SEGMENTATION_TOKENS_LENGTHmaps toNEXT_PUBLIC_INDEXING_MAX_SEGMENTATION_TOKENS_LENGTHMAX_TOOLS_NUMmaps toNEXT_PUBLIC_MAX_TOOLS_NUMLOOP_NODE_MAX_COUNTmaps toNEXT_PUBLIC_LOOP_NODE_MAX_COUNTMAX_PARALLEL_LIMITmaps toNEXT_PUBLIC_MAX_PARALLEL_LIMITMAX_ITERATIONS_NUMmaps toNEXT_PUBLIC_MAX_ITERATIONS_NUMMAX_TREE_DEPTHmaps toNEXT_PUBLIC_MAX_TREE_DEPTH
PM2 Launch (Line 46):
The script launches the Next.js application using PM2 with the following command:
pm2 start /app/web/server.js --name dify-web --cwd /app/web -i ${PM2_INSTANCES} --no-daemon
The -i ${PM2_INSTANCES} flag activates cluster mode, creating multiple worker processes. The --no-daemon flag ensures PM2 runs in the foreground as PID 1, which is required for Docker to properly manage the container lifecycle.
PM2 Configuration File (web/docker/pm2.json, 11 lines):
A companion JSON configuration file defines the default PM2 settings:
name:"dify-web"script:"/app/web/server.js"cwd:"/app/web"exec_mode:"cluster"instances:2(overridden byPM2_INSTANCESenv var at runtime)
The entrypoint script uses the CLI invocation rather than the JSON file, allowing the PM2_INSTANCES value to be dynamic.
Usage
This script is automatically executed when the langgenius/dify-web Docker image starts. It is not intended to be run manually. Configuration is controlled entirely through Docker Compose environment variables defined in the web service section of docker-compose.yaml (Lines 819-847).
Code Reference
Source Location
- Repository: Dify
- File:
web/docker/entrypoint.sh(Lines 1-47) - File:
web/docker/pm2.json(Lines 1-11)
Signature
#!/bin/bash
set -e
# Environment variable mappings
export NEXT_PUBLIC_DEPLOY_ENV=${DEPLOY_ENV}
export NEXT_PUBLIC_EDITION=${EDITION}
export NEXT_PUBLIC_BASE_PATH=${NEXT_PUBLIC_BASE_PATH}
export NEXT_PUBLIC_API_PREFIX=${CONSOLE_API_URL}/console/api
export NEXT_PUBLIC_PUBLIC_API_PREFIX=${APP_API_URL}/api
export NEXT_PUBLIC_MARKETPLACE_API_PREFIX=${MARKETPLACE_API_URL}/api/v1
export NEXT_PUBLIC_MARKETPLACE_URL_PREFIX=${MARKETPLACE_URL}
export NEXT_PUBLIC_COOKIE_DOMAIN=${NEXT_PUBLIC_COOKIE_DOMAIN}
export NEXT_PUBLIC_SENTRY_DSN=${SENTRY_DSN}
# ... (approximately 20 more mappings)
# Launch PM2 cluster
pm2 start /app/web/server.js --name dify-web --cwd /app/web -i ${PM2_INSTANCES} --no-daemon
Import
# This script is set as the Docker ENTRYPOINT in the Dockerfile.
# It is not imported or sourced manually.
# The Dockerfile directive is typically:
ENTRYPOINT ["/app/web/docker/entrypoint.sh"]
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
CONSOLE_API_URL |
String (URL) | No | Base URL for the console API backend. Suffix /console/api is appended. If empty, relative paths are used.
|
APP_API_URL |
String (URL) | No | Base URL for the public application API. Suffix /api is appended. If empty, relative paths are used.
|
MARKETPLACE_API_URL |
String (URL) | No | Base URL for the plugin marketplace API. Suffix /api/v1 is appended. Defaults to https://marketplace.dify.ai in Docker Compose.
|
SENTRY_DSN |
String (URL) | No | Sentry Data Source Name for frontend error tracking. |
DEPLOY_ENV |
String | No | Deployment environment label (PRODUCTION or TESTING). Controls UI color labels.
|
PM2_INSTANCES |
Integer | No | Number of PM2 cluster worker processes. Defaults to 2 in Docker Compose. |
CSP_WHITELIST |
String | No | Content Security Policy whitelist domains. |
ALLOW_EMBED |
String (boolean) | No | Whether to allow iframe embedding. Defaults to false.
|
TOP_K_MAX_VALUE |
Integer | No | Maximum top-K value for RAG retrieval UI. |
LOOP_NODE_MAX_COUNT |
Integer | No | Maximum loop iterations in workflow nodes. Defaults to 100. |
MAX_PARALLEL_LIMIT |
Integer | No | Maximum parallel execution limit in workflows. Defaults to 10. |
MAX_ITERATIONS_NUM |
Integer | No | Maximum number of iterations. Defaults to 99. |
MAX_TREE_DEPTH |
Integer | No | Maximum tree depth in workflows. Defaults to 50. |
Outputs
| Name | Type | Description |
|---|---|---|
| PM2-managed Next.js cluster | Running processes | A set of Node.js worker processes (count determined by PM2_INSTANCES) serving the Dify web frontend on the container's internal port (default 3000). PM2 runs as PID 1 in no-daemon mode.
|
NEXT_PUBLIC_* environment variables |
Process environment | Approximately 30 exported environment variables available to the Next.js server-side rendering process, enabling runtime configuration of API endpoints, feature flags, and UI behavior. |
Usage Examples
# The entrypoint runs automatically when the container starts.
# Configuration is done through Docker Compose environment variables.
# In docker-compose.yaml, the web service configuration:
# web:
# image: langgenius/dify-web:1.12.1
# environment:
# CONSOLE_API_URL: ${CONSOLE_API_URL:-}
# APP_API_URL: ${APP_API_URL:-}
# MARKETPLACE_API_URL: ${MARKETPLACE_API_URL:-https://marketplace.dify.ai}
# PM2_INSTANCES: ${PM2_INSTANCES:-2}
# TEXT_GENERATION_TIMEOUT_MS: ${TEXT_GENERATION_TIMEOUT_MS:-60000}
# CSP_WHITELIST: ${CSP_WHITELIST:-}
# ALLOW_EMBED: ${ALLOW_EMBED:-false}
# To verify the running processes inside the container:
docker exec -it dify-docker-web-1 pm2 list
# Expected output:
# +----------+----+-----+---------+----------+-------+-------+
# | id | name | mode | status | cpu | memory |
# +----------+----+-----+---------+----------+-------+-------+
# | 0 | dify-web | cluster | online | 0% | 85 MB |
# | 1 | dify-web | cluster | online | 0% | 82 MB |
# +----------+----+-----+---------+----------+-------+-------+
# To scale PM2 instances, update .env and restart:
# In .env:
# PM2_INSTANCES=4
docker compose restart web
# To debug environment variable mapping, inspect inside the container:
docker exec -it dify-docker-web-1 env | grep NEXT_PUBLIC