| 用途 | 构建期使用 SSH 私钥拉代码 |
|---|---|
| 语法 | RUN --mount=type=ssh git clone git@example.com:team/repo.git |
| 构建侧 | docker build --ssh default . |
示例
示例
RUN --mount=type=ssh \
git clone --depth 1 git@example.com:team/repo.git /src/repo \
&& rm -rf /src/repo/.git需要宿主 ssh-agent 已加载对应私钥(ssh-add -l 检查);容器内 known_hosts 可提前 ssh-keyscan 写入。