3

上下文如下:

  • 詹金斯
  • Kubernetes 插件
  • Docker-in-Docker/dind 容器
  • 多阶段 Dockerfile

流程如下所示:

  1. 拉建设者docker pull repo/image:builder
  2. 构建构建器DOCKER_BUILDKIT=1 docker build . --build-arg BUILDKIT_INLINE_CACHE=1 --target builder --cache-from repo/image:builder --tag repo/image:builder
  3. 推送生成器docker push repo/image:builder
  4. 拉图像docker pull repo/image:tag
  5. 构建镜像DOCKER_BUILDKIT=1 docker build . --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from repo/image:builder --cache-from repo/image:tag --tag repo/image:tag
  6. 推送图片docker push repo/image:tag

Dockerfile:

FROM node:8.16.0 as builder

WORKDIR /app
RUN mkdir /app/frontend
COPY frontend/package.json /app/frontend/
WORKDIR /app/frontend
RUN npm install
COPY frontend /app/frontend
RUN npm run build
FROM nginx:1.13.8-alpine
WORKDIR /project/web
COPY --from=builder --chown=nginx:nginx /app/frontend/built /project/web/public

COPY --from=builder --chown=nginx:nginx /app/frontend/built /project/web/publicdocker build 永远卡住(30-40 分钟后我手动停止它)没有错误。

编辑:在第一次运行时,当注册表中还没有图像时,构建器缓存并按COPY --from=builder预期工作。只有从第二个版本开始,它才会卡在COPY --from=builder

4

0 回答 0