Fix and update

This commit is contained in:
baohua
2026-02-09 11:34:35 -08:00
parent 784c989789
commit bb94a9f617
136 changed files with 2146 additions and 262 deletions

View File

@@ -8,6 +8,8 @@
### `Dockerfile` 新增指令详解
BuildKit 引入了多项新指令旨在优化构建缓存和安全性以下将详细介绍这些指令的用法
使用 BuildKit 我们可以使用下面几个新的 `Dockerfile` 指令来加快镜像构建
要使用最新的 Dockerfile 语法特性建议在 Dockerfile 开头添加语法指令
@@ -51,6 +53,7 @@ COPY --from=builder /app/dist /app/dist
```docker
## syntax=docker/dockerfile:1
FROM node:alpine as builder
WORKDIR /app
@@ -65,6 +68,7 @@ COPY src /app/src
RUN --mount=type=cache,target=/app/node_modules,id=my_app_npm_module,sharing=locked \
## --mount=type=cache,target=/app/dist,id=my_app_dist,sharing=locked \
npm run build
FROM nginx:alpine
@@ -72,6 +76,7 @@ FROM nginx:alpine
## COPY --from=builder /app/dist /app/dist
## 为了更直观的说明 from 和 source 指令,这里使用 RUN 指令
RUN --mount=type=cache,target=/tmp/dist,from=builder,source=/app/dist \
# --mount=type=cache,target/tmp/dist,from=my_app_dist,sharing=locked \
mkdir -p /app/dist && cp -r /tmp/dist/* /app/dist
@@ -101,6 +106,7 @@ RUN --mount=type=cache,target=/tmp/dist,from=builder,source=/app/dist \
```docker
## syntax=docker/dockerfile:1
RUN --mount=type=bind,from=php:alpine,source=/usr/local/bin/docker-php-entrypoint,target=/docker-php-entrypoint \
cat /docker-php-entrypoint
```
@@ -111,6 +117,7 @@ RUN --mount=type=bind,from=php:alpine,source=/usr/local/bin/docker-php-entrypoin
```docker
## syntax=docker/dockerfile:1
RUN --mount=type=tmpfs,target=/temp \
mount | grep /temp
```
@@ -121,6 +128,7 @@ RUN --mount=type=tmpfs,target=/temp \
```docker
## syntax=docker/dockerfile:1
RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \
cat /root/.aws/credentials
```
@@ -135,6 +143,7 @@ $ docker build -t test --secret id=aws,src=$HOME/.aws/credentials .
```docker
## syntax=docker/dockerfile:1
FROM alpine
RUN apk add --no-cache openssh-client
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
@@ -150,6 +159,8 @@ $ docker build -t test --ssh default=$SSH_AUTH_SOCK .
### docker compose build 使用 BuildKit
Docker Compose 同样支持 BuildKit这使得多服务应用的构建更加高效
Docker 23.0 BuildKit 已默认启用无需额外配置如果使用旧版本可设置 `DOCKER_BUILDKIT=1` 环境变量启用
### 官方文档