Add new content and update versions

This commit is contained in:
yeasy
2026-04-19 22:35:33 -07:00
parent 1d780f70c5
commit b3d1508310
18 changed files with 122 additions and 31 deletions
+10
View File
@@ -186,4 +186,14 @@ HEALTHCHECK --start-period=60s CMD curl -f http://localhost/ || exit 1
健康检查应主要关注 **当前服务** 是否可用而不是检查其下游依赖 (数据库等)下游依赖的检查应由应用逻辑处理
#### 5. 与容器编排平台的关系
不同平台对 HEALTHCHECK 的支持有所不同
- **Docker Compose**直接使用 Dockerfile 中定义的 HEALTHCHECK也可在 `compose.yaml` 中覆盖
- **Docker Swarm**使用 HEALTHCHECK 进行服务健康判断和滚动更新决策
- **Kubernetes****忽略** Dockerfile 中的 HEALTHCHECK使用自己的 `livenessProbe` `readinessProbe` 机制
如果应用同时部署在 Docker Compose Kubernetes 环境中建议在 Dockerfile 中保留 HEALTHCHECK Compose 使用同时在 Kubernetes Pod 配置中定义对应的探针
---
+37
View File
@@ -158,4 +158,41 @@ RUN --mount=type=cache,target=/go/pkg/mod \
RUN --mount=type=secret,id=mysecret \
cat /run/secrets/mysecret
```
#### 3. Heredoc 语法
BuildKit 支持使用 heredoc 语法编写多行脚本无需行末反斜杠 `\` 连接
```docker
RUN <<EOF
apt-get update
apt-get install -y \
build-essential \
curl \
git
rm -rf /var/lib/apt/lists/*
EOF
```
优势
- 可读性更强不需要在每行末尾添加 `\`
- 避免在脚本中转义引号
- 支持多个 heredoc 可指定不同的 Shell
```docker
RUN <<EOF
echo "使用默认 /bin/sh"
EOF
RUN <<'EOF'
#!/bin/bash
set -euo pipefail
echo "使用 bash"
wget http://example.com/file.tar.gz
EOF
```
> 💡 使用 heredoc 需要在 Dockerfile 首行声明 BuildKit 语法版本`# syntax=docker/dockerfile:1`
---
+5
View File
@@ -203,6 +203,11 @@ COPY --link --from=builder /app/dist /usr/share/nginx/html
- 并行化构建过程
- 加速多阶段构建
> **注意**使用 `--link` 需要满足以下条件
> - 启用 BuildKitDocker Engine 23.0+ 默认启用
> - Dockerfile 语法版本 1.4 或更高在首行声明 `# syntax=docker/dockerfile:1`
> - 目标路径在前序指令中应不存在或为空目录
---
### 7.2.9 dockerignore