Add new content and update versions

This commit is contained in:
yeasy
2026-04-19 22:35:33 -07:00
parent 14851771a8
commit 258ef59727
18 changed files with 122 additions and 31 deletions
+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`
---