上下文如下:
- 詹金斯
- Kubernetes 插件
- Docker-in-Docker/dind 容器
- 多阶段 Dockerfile
流程如下所示:
- 拉建设者
docker pull repo/image:builder
- 构建构建器
DOCKER_BUILDKIT=1 docker build . --build-arg BUILDKIT_INLINE_CACHE=1 --target builder --cache-from repo/image:builder --tag repo/image:builder
- 推送生成器
docker push repo/image:builder
- 拉图像
docker pull repo/image:tag
- 构建镜像
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
- 推送图片
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/public
docker build 永远卡住(30-40 分钟后我手动停止它)没有错误。
编辑:在第一次运行时,当注册表中还没有图像时,构建器缓存并按COPY --from=builder
预期工作。只有从第二个版本开始,它才会卡在COPY --from=builder