Implementation:Langgenius Dify Env Template Copy
| Knowledge Sources | |
|---|---|
| Domains | DevOps Configuration Management Docker |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
The Env Template Copy operation bootstraps a Dify deployment's runtime configuration by copying the canonical .env.example template to a local .env file that can be customized with deployment-specific values.
Description
The docker/.env.example file (1,522 lines) is the single source of truth for all configurable environment variables in a Dify Docker deployment. It contains approximately 300 environment variables organized into clearly commented sections:
- Common Variables (Lines 1-64): Service URLs including
CONSOLE_API_URL,CONSOLE_WEB_URL,SERVICE_API_URL,APP_API_URL,APP_WEB_URL,FILES_URL, andINTERNAL_FILES_URL. Also sets locale defaults (LANG=C.UTF-8,LC_ALL=C.UTF-8,PYTHONIOENCODING=utf-8).
- Server Configuration (Lines 65-170): Logging settings (
LOG_LEVEL,LOG_OUTPUT_FORMAT,LOG_FILE), debug flags (DEBUG,FLASK_DEBUG), security (SECRET_KEY,INIT_PASSWORD), deployment mode (DEPLOY_ENV), server tuning (SERVER_WORKER_AMOUNT,SERVER_WORKER_CLASS=gevent,GUNICORN_TIMEOUT), and Celery worker configuration (CELERY_WORKER_AMOUNT,CELERY_AUTO_SCALE).
- Database Configuration: PostgreSQL settings (
DB_USERNAME,DB_PASSWORD,DB_HOST,DB_PORT,DB_DATABASE) with connection pool tuning (SQLALCHEMY_POOL_SIZE=30,SQLALCHEMY_MAX_OVERFLOW=10,SQLALCHEMY_POOL_RECYCLE=3600).
- Redis Configuration: Connection details (
REDIS_HOST,REDIS_PORT,REDIS_PASSWORD), SSL options, Sentinel support (REDIS_USE_SENTINEL,REDIS_SENTINELS), and cluster mode (REDIS_USE_CLUSTERS).
- Storage Configuration: Backend selection (
STORAGE_TYPE) with full configuration blocks for local storage, S3, Azure Blob, Google Cloud Storage, Tencent COS, Huawei OBS, Volcengine TOS, Baidu OBS, and Alibaba Cloud OSS.
- Vector Store Configuration: Selection variable (
VECTOR_STORE) with dedicated sections for Weaviate, Qdrant, Milvus, Zilliz, PGVector, Chroma, OpenSearch, TiDB Vector, Oracle, Relyt, Tencent, Elasticsearch, and more.
- Nginx and SSL: Reverse proxy settings (
NGINX_SERVER_NAME,NGINX_HTTPS_ENABLED,NGINX_SSL_PORT,NGINX_SSL_CERT_FILENAME).
- Plugin Daemon: Plugin system configuration (
PLUGIN_DAEMON_PORT,PLUGIN_DAEMON_KEY,PLUGIN_MAX_PACKAGE_SIZE).
The cp command creates a local copy that Docker Compose automatically reads when launching services. The user then edits the .env file to customize values for their specific deployment.
Usage
This is the first step in any new Dify Docker deployment. Run the copy command once before executing docker compose up -d. After copying, review and modify at minimum:
SECRET_KEY-- generate a strong unique keyDB_PASSWORDandREDIS_PASSWORD-- set secure passwords- Service URLs if deploying behind a custom domain
STORAGE_TYPEand associated credentials if using cloud storage
Code Reference
Source Location
- Repository: Dify
- File:
docker/.env.example(Lines 1-1522)
Signature
cp docker/.env.example docker/.env
Import
# No import required -- this is a shell command executed from the repository root.
cd dify/docker
cp .env.example .env
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
.env.example |
File (text) | Yes | The canonical environment variable template containing ~300 variables with documented defaults, comments, and section headers. |
Outputs
| Name | Type | Description |
|---|---|---|
.env |
File (text) | A local copy of the template that Docker Compose reads automatically. This file should be edited with deployment-specific values and must not be committed to version control. |
Usage Examples
# Standard deployment setup
cd dify/docker
cp .env.example .env
# Generate a secure SECRET_KEY and update .env
SECRET_KEY=$(openssl rand -base64 42)
sed -i "s/^SECRET_KEY=.*/SECRET_KEY=${SECRET_KEY}/" .env
# Set custom database password
sed -i "s/^DB_PASSWORD=.*/DB_PASSWORD=my_secure_db_password/" .env
# Set custom Redis password
sed -i "s/^REDIS_PASSWORD=.*/REDIS_PASSWORD=my_secure_redis_password/" .env
# Configure external domain URLs
sed -i "s|^CONSOLE_API_URL=.*|CONSOLE_API_URL=https://api.console.example.com|" .env
sed -i "s|^APP_API_URL=.*|APP_API_URL=https://api.app.example.com|" .env
# Verify configuration before launch
grep -c "^[^#]*=" .env
# Expected output: approximately 300 (number of configured variables)
# Launch the stack
docker compose up -d