render-docker
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRender Docker Deployments
Render Docker 部署
Render uses BuildKit for Docker builds. All compute service types that support custom runtimes can use (build from a Dockerfile in the repo) or (pull a prebuilt image; no Dockerfile build on Render). Deeper patterns and copy-paste templates live under .
runtime: dockerruntime: imagereferences/Render 使用 BuildKit 进行 Docker 构建。所有支持自定义运行时的计算服务类型都可使用 (从仓库中的Dockerfile构建)或 (拉取预构建镜像;不在Render上构建Dockerfile)。更深入的模式和可复制模板位于 目录下。
runtime: dockerruntime: imagereferences/When to Use
适用场景
- Authoring or debugging a Dockerfile for a Render service
- Choosing vs
runtime: dockerin a Blueprintruntime: image - Wiring private base images or prebuilt images with registry credentials
- Multi-stage builds, build args, secrets, and layer caching
- Performance and security hardening of container images on Render
For full Blueprint authoring, see render-blueprints. For end-to-end deploy flows, see render-deploy.
- 为Render服务编写或调试 Dockerfile
- 在Blueprint中选择 还是
runtime: dockerruntime: image - 为私有基础镜像或预构建镜像配置仓库凭证
- 多阶段构建、构建参数、密钥和层缓存相关操作
- 在Render上对容器镜像进行性能和安全加固
如需完整的Blueprint编写指南,请查看 render-blueprints。如需端到端部署流程,请查看 render-deploy。
Render Docker Builds
Render Docker 构建
- BuildKit is used for Docker builds on Render.
- : Render builds an image from your repo using
runtime: docker,dockerfilePath, and optionaldockerContext(overrides imagedockerCommand).CMD - : Render pulls
runtime: image; no repo-based image build. Pair withimage.urlwhen the registry is private.registryCredential
- Render上的Docker构建使用 BuildKit。
- :Render使用
runtime: docker、dockerfilePath和可选的dockerContext(覆盖镜像的dockerCommand)从你的仓库构建镜像。CMD - :Render拉取
runtime: image指定的镜像;不基于仓库构建镜像。当仓库为私有时,需搭配image.url使用。registryCredential
Blueprint Configuration
Blueprint 配置
| Field | Role |
|---|---|
| Path to the Dockerfile (default |
| Build context directory (what is sent to the daemon) |
| Overrides the container |
| Image reference for |
| Auth for private pulls; often |
Example sketch (values illustrative):
yaml
services:
- type: web
name: api
runtime: docker
region: oregon
plan: starter
dockerfilePath: ./Dockerfile
dockerContext: .
dockerCommand: node server.js
envVars:
- key: PORT
value: 10000For , set and, if needed, per Registry Configuration below.
runtime: imageimage.urlregistryCredential| 字段 | 作用 |
|---|---|
| Dockerfile的路径(默认值为 |
| 构建上下文目录(即发送给守护进程的内容) |
| 镜像构建完成后覆盖容器的 |
| |
| 私有镜像拉取的认证信息;通常使用 |
示例配置(仅作演示):
yaml
services:
- type: web
name: api
runtime: docker
region: oregon
plan: starter
dockerfilePath: ./Dockerfile
dockerContext: .
dockerCommand: node server.js
envVars:
- key: PORT
value: 10000对于 模式,需设置 ,若有需要,可按照下方仓库配置设置 。
runtime: imageimage.urlregistryCredentialMulti-Stage Builds
多阶段构建
Recommended for production. Use a builder stage for compilation and dependency installation, and a minimal runner stage that only copies artifacts and runtime files. Benefits:
- Smaller images and faster pulls
- Fewer tools and secrets in the final image (smaller attack surface)
- Clear separation between build-time and run-time dependencies
See for language-specific templates.
references/dockerfile-patterns.md生产环境推荐使用。使用一个构建器阶段进行编译和依赖安装,再使用一个精简的运行器阶段仅复制产物和运行时文件。优势如下:
- 镜像体积更小,拉取速度更快
- 最终镜像中包含的工具和密钥更少(缩小攻击面)
- 清晰区分构建时依赖和运行时依赖
如需语言特定模板,请查看 。
references/dockerfile-patterns.mdBuild Args vs Secrets
构建参数 vs 密钥
Critical: Never pass secrets via . Build arguments are stored in image layers and can be recovered from the image history or intermediate layers.
ARG- Prefer runtime environment variables (Render env vars / secret files) for application secrets.
- For build-time secrets (e.g. private package feeds), use Docker BuildKit secret mounts () rather than
RUN --mount=type=secret,....ARG
Treat anything sensitive as runtime or BuildKit secret mount, not as a build arg.
重点注意: 切勿通过传递密钥。构建参数会存储在镜像层中,可从镜像历史或中间层恢复。
ARG- 应用密钥优先使用运行时环境变量(Render的环境变量/密钥文件)。
- 对于构建时密钥(如私有包源),请使用 Docker BuildKit密钥挂载()而非
RUN --mount=type=secret,...。ARG
任何敏感信息都应作为运行时变量或BuildKit密钥挂载处理,而非构建参数。
Registry Configuration
仓库配置
Private base images (for ) or prebuilt images () need authentication:
runtime: dockerruntime: image- Store credentials in the Render Dashboard under Registry Credentials.
- In Blueprint, reference them with (match the Dashboard name).
registryCredential.fromRegistryCreds.name
Supports common registries (Docker Hub, GHCR, ECR, Google Artifact Registry, and others). Step-by-step per provider: .
references/registry-setup.mdPrebuilt image services do not auto-deploy when the tag moves in the registry; trigger a manual redeploy or use a deploy hook when you publish a new image.
私有基础镜像(用于)或预构建镜像()需要进行身份认证:
runtime: dockerruntime: image- 在Render Dashboard的Registry Credentials中存储凭证。
- 在Blueprint中,通过 引用这些凭证(需与Dashboard中的名称匹配)。
registryCredential.fromRegistryCreds.name
支持常见镜像仓库(Docker Hub、GHCR、ECR、Google Artifact Registry等)。各提供商的分步指南请查看 。
references/registry-setup.md预构建镜像服务不会在仓库中标签更新时自动部署;发布新镜像时,请触发手动重新部署或使用部署钩子。
Layer Caching
层缓存
- Render caches Docker layers between builds; order Dockerfile instructions so that frequently unchanged layers stay early (see ).
references/optimization-guide.md - Tags and caching: mutable tags like can resolve to stale cached images. Prefer immutable references: digest (
latest) or version pins (repo/image@sha256:...).v1.2.3
- Render在构建之间会缓存Docker层;调整Dockerfile指令顺序,让不常变更的层排在前面(详情请查看 )。
references/optimization-guide.md - 标签与缓存:像**这类可变标签可能会解析为过期缓存的镜像。优先使用不可变引用:摘要(
latest)或版本固定标签**(repo/image@sha256:...)。v1.2.3
Platform Specifics
平台细节
- Render builds linux/amd64. Avoid assumptions about other architectures in production images.
- Port binding matches native services: bind HTTP to (Render sets
0.0.0.0:$PORT).PORT - Health checks behave like non-Docker web services (, etc.).
healthCheckPath - Secret files from Render appear under — do not rely on repo-root secret paths inside the container unless you copy or mount them explicitly in the image.
/etc/secrets/
- Render构建 linux/amd64 架构的镜像。生产环境镜像中请勿假设其他架构。
- 端口绑定与原生服务一致:将HTTP绑定到 (Render会设置
0.0.0.0:$PORT变量)。PORT - 健康检查的行为与非Docker Web服务一致(如等字段)。
healthCheckPath - Render提供的密钥文件位于 目录下——除非你在镜像中明确复制或挂载,否则不要依赖容器内仓库根目录的密钥路径。
/etc/secrets/
.dockerignore
and Start Commands
.dockerignore.dockerignore
与启动命令
.dockerignore- Always maintain a that excludes
.dockerignore,node_modules,.git, build artifacts, logs, and OS junk. This shrinks context upload time and avoids leaking local files into layers. Lists and rationale:.env.references/optimization-guide.md - Custom start command: if you need multiple shell steps, use a single shell form, e.g. (prefer
/bin/sh -c 'set -e; ./migrate && exec node server.js'so your app receives signals for graceful shutdown).exec
- 务必维护一个 文件,排除
.dockerignore、node_modules、.git、构建产物、日志和系统垃圾文件。这会缩小上下文上传时间,避免本地文件泄露到镜像层中。详细列表和原理请查看.env。references/optimization-guide.md - 自定义启动命令:如果需要多个Shell步骤,请使用单个Shell命令形式,例如 (优先使用
/bin/sh -c 'set -e; ./migrate && exec node server.js',以便你的应用接收信号实现优雅关闭)。exec
References
参考文档
| Document | Contents |
|---|---|
| Multi-stage templates (Node, Python, Go, Ruby, Rust, static sites) |
| Docker Hub, GHCR, ECR, Artifact Registry + Blueprint wiring |
| Layer order, |
| 文档 | 内容 |
|---|---|
| 多阶段构建模板(Node、Python、Go、Ruby、Rust、静态站点) |
| Docker Hub、GHCR、ECR、Artifact Registry的配置及Blueprint关联方法 |
| 层顺序、 |
Related Skills
相关技能
- render-deploy — Deploy flows, Blueprint vs Dashboard, operational steps
- render-blueprints — Full schema, wiring, and validation
render.yaml - render-web-services — Web service behavior, health checks, and HTTP edge cases
- render-deploy —— 部署流程、Blueprint与Dashboard对比、操作步骤
- render-blueprints —— 完整的schema、配置及验证
render.yaml - render-web-services —— Web服务行为、健康检查及HTTP边缘情况