有没有办法让
Dockerfile
的 COPY
命令跳过 Git 子模块?
我知道我可以设置
.dockerignore
,但我想知道是否可以在没有 .dockerignore
的情况下跳过 Git 子模块。
您可能会考虑多阶段构建:
# First Stage: Clone repository without submodules
FROM alpine AS clone-stage
RUN apk add --no-cache git \
&& git clone --recurse-submodules=no https://github.com/your-repo.git /temp-dir
# Second Stage: Copy the cloned data
FROM your-base-image
COPY --from=clone-stage /temp-dir /your-destination-dir
最终图像中没有子模块。