render-env-vars

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Environment Variables on Render

Render 上的环境变量

Render exposes configuration to services as environment variables. Values are always strings at the platform layer—applications must parse numbers, booleans, and structured data explicitly.
There are three primary ways to set variables:
  1. Render Dashboard — per-service UI, bulk import from
    .env
    , save/redeploy options
  2. Blueprint
    envVars
    (and related keys) in
    render.yaml
  3. MCP / API — e.g.
    update_environment_variables
    on a service
Deep wiring patterns, full platform variable tables, and language-specific notes live under
references/
.
Render 以环境变量的形式向服务公开配置。在平台层,值始终是字符串——应用程序必须显式解析数字、布尔值和结构化数据。
设置变量主要有三种方式:
  1. Render 仪表板 — 每个服务的专属UI,支持从
    .env
    批量导入,提供保存/重新部署选项
  2. Blueprint
    render.yaml
    中的
    envVars
    (及相关键)
  3. MCP / API — 例如对服务执行
    update_environment_variables
    操作
深度关联模式、完整平台变量表和语言相关说明可查看
references/
目录下的内容。

When to Use This Skill

何时使用此技能

Use this skill when users want to:
  • Add, change, or remove environment variables or secrets
  • Understand Dashboard vs Blueprint vs API/MCP flows
  • Use environment groups for shared configuration
  • Wire
    fromDatabase
    ,
    fromService
    ,
    fromGroup
    ,
    sync: false
    , or
    generateValue
    in Blueprints
  • Debug missing vars, secret files, precedence, or platform-injected names
For full Blueprint authoring, pair with render-blueprints. For first-time deploys, render-deploy. For web service behavior and ports, render-web-services.
当用户需要以下操作时,可使用此技能:
  • 添加、修改或删除环境变量或密钥
  • 了解仪表板、Blueprint与API/MCP的操作流程差异
  • 使用环境组实现共享配置
  • 在Blueprint中配置
    fromDatabase
    fromService
    fromGroup
    sync: false
    generateValue
  • 调试缺失的变量、密钥文件、优先级问题或平台注入的变量名称
如需完整的Blueprint编写指导,请搭配render-blueprints技能。首次部署请使用render-deploy技能。Web服务行为与端口相关问题请使用render-web-services技能。

Setting Variables

设置变量

Dashboard

仪表板

  • Add variables individually (name + value) or in bulk by pasting/uploading a
    .env
    -style file.
  • Save options typically include:
    • Save and rebuild & deploy — picks up build-time changes
    • Deploy only — runtime change without a full rebuild (when applicable)
    • Save only — persist without triggering a deploy
Use Dashboard edits when iterating quickly or when the repo should not carry certain values.
  • 可以单独添加变量(名称+值),也可以通过粘贴/上传
    .env
    格式的文件批量添加
  • 保存选项通常包括:
    • 保存并重新构建与部署 — 应用构建阶段的变更
    • 仅部署 — 仅应用运行时变更,无需完整重建(适用时)
    • 仅保存 — 保存变更但不触发部署
快速迭代或仓库不应包含特定值时,适合使用仪表板编辑。

Blueprint (
render.yaml
)

Blueprint(
render.yaml

Declare
envVars
on each service. Values can be literals, generated secrets, sync-disabled prompts, or references to databases, other services, or env groups. See Blueprint Wiring below and
references/wiring-reference.md
for exhaustive patterns and YAML.
在每个服务中声明
envVars
。值可以是字面量、生成的密钥、禁用同步的提示,或是对数据库、其他服务或环境组的引用。详细模式与YAML示例请查看下方的Blueprint关联以及
references/wiring-reference.md

MCP / API

MCP / API

Automation tools can set variables on existing services (e.g.
update_environment_variables
). Useful for CI, rotation, or keeping Dashboard state in sync with external secret stores—without committing secrets to Git.
自动化工具可对现有服务设置变量(例如
update_environment_variables
)。适用于CI流程、密钥轮换,或保持仪表板状态与外部密钥存储同步——无需将密钥提交到Git。

Secret Management

密钥管理

  • sync: false
    — Render prompts in the Dashboard for the value only on initial Blueprint setup when the resource is first created. On Blueprint updates,
    sync: false
    is ignored (values are not re-prompted from the file alone). These vars are excluded from preview environments and are invalid inside environment groups.
  • generateValue: true
    — Render generates a base64-encoded 256-bit random value at provision time. Use for passwords, signing keys, or tokens that do not need human-chosen values.
  • Never commit real secrets in
    render.yaml
    as plain
    value:
    entries. Prefer Dashboard, secret manager integration,
    generateValue
    , or
    sync: false
    with Dashboard entry.
  • sync: false
    — 仅在首次创建资源、初始设置Blueprint时,Render会在仪表盘中提示输入值。在Blueprint更新时,
    sync: false
    会被忽略(不会仅通过文件重新提示输入值)。这些变量不会出现在预览环境中,且在环境组内无效
  • generateValue: true
    — Render会在配置阶段生成一个base64编码的256位随机值。适用于密码、签名密钥或无需人工指定值的令牌。
  • 切勿在
    render.yaml
    中以明文
    value:
    条目提交真实密钥。优先使用仪表板、密钥管理器集成、
    generateValue
    ,或结合
    sync: false
    在仪表板中输入值。

Secret files

密钥文件

  • Store sensitive file content as secret files (not inline env strings). They appear as plaintext files under
    /etc/secrets/<filename>
    .
  • Combined limit: 1 MB total secret file payload per service or per linked env group (as applicable to your setup).
  • Docker: secret files are available under
    /etc/secrets/
    on the running instance.
  • 将敏感文件内容存储为密钥文件(而非内联环境字符串)。它们会以明文文件的形式出现在**
    /etc/secrets/<filename>
    **路径下。
  • 总限制:每个服务或每个关联的环境组的密钥文件总 payload 为1 MB(取决于你的配置)。
  • Docker:密钥文件在运行实例中位于**
    /etc/secrets/
    **路径下。

Environment Groups

环境组

Environment groups are named collections of variables linked to multiple services.
  • Precedence: Service-level variables override variables from linked groups with the same name.
  • Multiple groups on one service: the group that was most recently created wins for overlapping keys. This ordering is not documented as stable—avoid relying on it; use distinct names or consolidate groups.
  • Groups can be scoped to a project environment so staging and production differ without duplicating every service definition.
环境组是关联到多个服务的命名变量集合。
  • 优先级服务级变量会覆盖同名的组变量。
  • 单个服务关联多个组:对于重复的键,最近创建的组生效。此排序未被记录为稳定状态——避免依赖该规则;请使用不同的名称或合并组。
  • 组可以限定在项目环境中,这样 staging 和 production 环境无需重复每个服务定义即可实现差异配置。

Blueprint Wiring (Summary)

Blueprint关联(摘要)

Full syntax, examples, and edge cases:
references/wiring-reference.md
. Authoritative Blueprint docs: render-blueprints skill.
MechanismRole
value
Hardcoded string (non-secret config only)
generateValue: true
Platform-generated secret
sync: false
Dashboard prompt on initial create only
fromDatabase
Inject DB fields (
connectionString
,
host
,
port
,
user
,
password
,
database
)
fromService
Key Value:
type: keyvalue
+ properties; private/web:
host
,
hostport
, or
envVarKey
fromGroup
Link all vars from a named group
完整语法、示例与边缘情况请查看:
references/wiring-reference.md
。权威Blueprint文档请参考render-blueprints技能。
机制作用
value
硬编码字符串(仅适用于非机密配置)
generateValue: true
平台生成的密钥
sync: false
仅在初始创建时触发仪表板提示
fromDatabase
注入数据库字段(
connectionString
host
port
user
password
database
fromService
键值对:
type: keyvalue
+ 属性;私有/ Web服务:
host
hostport
envVarKey
fromGroup
关联指定组的所有变量

Platform-Injected Variables

平台注入变量

Render sets read-only variables your app can read at runtime (and some at build). A concise list:
VariableTypical meaning
RENDER
"true"
when running on Render
RENDER_SERVICE_TYPE
Service kind (e.g. web, worker)
RENDER_SERVICE_ID
Service identifier
RENDER_SERVICE_NAME
Human-readable service name
RENDER_INSTANCE_ID
Current instance
RENDER_EXTERNAL_URL
Public URL (when applicable)
RENDER_EXTERNAL_HOSTNAME
Public hostname
RENDER_DISCOVERY_SERVICE
Service discovery hostname (private network)
RENDER_GIT_COMMIT
Deployed commit SHA
RENDER_GIT_BRANCH
Branch for this deploy
PORT
HTTP port to bind (default
10000
)
IS_PULL_REQUEST
Preview deploy indicator
RENDER_CPU_COUNT
vCPU count for the instance
RENDER_WEB_CONCURRENCY
Suggested worker/process count hint
Build vs runtime availability, language version env vars, and WEB_CONCURRENCY defaults:
references/platform-variables.md
.
Render会设置只读变量,你的应用可在运行时(部分在构建时)读取。简要列表如下:
变量典型含义
RENDER
在Render上运行时为
"true"
RENDER_SERVICE_TYPE
服务类型(例如web、worker)
RENDER_SERVICE_ID
服务标识符
RENDER_SERVICE_NAME
人类可读的服务名称
RENDER_INSTANCE_ID
当前实例
RENDER_EXTERNAL_URL
公开URL(适用时)
RENDER_EXTERNAL_HOSTNAME
公开主机名
RENDER_DISCOVERY_SERVICE
服务发现主机名(私有网络)
RENDER_GIT_COMMIT
已部署的提交SHA
RENDER_GIT_BRANCH
本次部署的分支
PORT
HTTP绑定端口(默认
10000
IS_PULL_REQUEST
预览部署标识
RENDER_CPU_COUNT
实例的vCPU数量
RENDER_WEB_CONCURRENCY
建议的工作进程/进程数量提示
构建时与运行时的可用性、语言版本环境变量以及WEB_CONCURRENCY默认值请查看
references/platform-variables.md

Runtime-Specific Defaults

运行时特定默认值

Render and buildpacks may set defaults (verify in your service’s Environment tab):
RuntimeNotable defaults
Node.js
NODE_ENV=production
Python
PYTHON_VERSION
(pinned by build); Gunicorn-oriented images often set
GUNICORN_CMD_ARGS
to bind
0.0.0.0:10000
Ruby
RAILS_ENV=production
,
RAILS_LOG_TO_STDOUT=true
Go
GO111MODULE=on
(legacy modules flag; still seen on older stacks)
Rust
ROCKET_PORT=10000
(Rocket convention)
Always bind HTTP servers to
0.0.0.0
and
PORT
(or the stack’s documented port env) unless using a static site or custom Docker entrypoint.
Render与buildpack可能会设置默认值(请在服务的环境标签页中验证):
运行时值得注意的默认值
Node.js
NODE_ENV=production
Python
PYTHON_VERSION
(由build固定);基于Gunicorn的镜像通常会设置
GUNICORN_CMD_ARGS
以绑定**
0.0.0.0:10000
**
Ruby
RAILS_ENV=production
,
RAILS_LOG_TO_STDOUT=true
Go
GO111MODULE=on
(旧版模块标志;仍会在较旧的栈中出现)
Rust
ROCKET_PORT=10000
(Rocket框架约定)
除非使用静态站点或自定义Docker入口点,否则请始终将HTTP服务器绑定到**
0.0.0.0
PORT
**(或栈文档中指定的端口环境变量)。

Common Issues

常见问题

  1. Everything is a string
    DEBUG=false
    is truthy in many parsers; use explicit comparison or typed config loaders.
  2. WEB_CONCURRENCY
    — Default behavior changed for services created after December 8, 2025. Compare with older services when debugging worker counts; see
    references/platform-variables.md
    .
  3. Undocumented
    RENDER_*
    variables
    — Names and semantics may change; do not depend on undocumented injection for critical logic.
  4. Blueprint vs Dashboard drift — Editing only
    render.yaml
    does not retroactively apply
    sync: false
    prompts on update; merge strategy for env keys is easy to misunderstand—test in a scratch service.
  5. Secret file paths — Code must read
    /etc/secrets/<filename>
    ; wrong paths or missing mounts usually show as file-not-found at runtime.
  1. 所有值都是字符串 — 在许多解析器中
    DEBUG=false
    会被视为真值;请使用显式比较或类型化配置加载器。
  2. WEB_CONCURRENCY
    — 对于2025年12月8日之后创建的服务,默认行为已更改。调试工作进程数量时请与旧服务对比;详情请查看
    references/platform-variables.md
  3. 未记录的
    RENDER_*
    变量
    — 名称与语义可能会更改;不要依赖未记录的注入变量实现关键逻辑。
  4. Blueprint与仪表板配置漂移 — 仅编辑
    render.yaml
    不会在更新时回溯应用
    sync: false
    提示;环境键的合并策略容易被误解——请在测试服务中验证。
  5. 密钥文件路径 — 代码必须读取**
    /etc/secrets/<filename>
    **;错误的路径或缺失的挂载通常会在运行时显示为文件未找到。

References

参考资料

  • references/wiring-reference.md
    — Complete Blueprint
    envVar
    wiring, YAML examples, precedence, edge cases
  • references/platform-variables.md
    — Injected variables (build vs runtime), language versions, concurrency, reading vars from code
  • references/wiring-reference.md
    — 完整的Blueprint
    envVar
    关联、YAML示例、优先级与边缘情况
  • references/platform-variables.md
    — 注入变量(构建时vs运行时)、语言版本、并发、从代码中读取变量

Related Skills

相关技能

  • render-blueprints — Full Blueprint authoring, validation, multi-service layouts
  • render-deploy — First deploy, repo requirements, MCP vs YAML
  • render-web-services — Ports, health checks, scaling behavior tied to env-driven servers
  • render-blueprints — 完整的Blueprint编写、验证、多服务布局
  • render-deploy — 首次部署、仓库要求、MCP与YAML对比
  • render-web-services — 端口、健康检查、与环境驱动服务器相关的扩缩容行为