Why does Multi-stage docker build get stuck at "COPY --from=builder ..."

4/6/2020

The context is as follows:

  • Jenkins
  • Kubernetes plugin
  • Docker-in-Docker/dind container
  • Multi-stage Dockerfile

The flow looks as follows:

  1. pull builder docker pull repo/image:builder
  2. build builder DOCKER_BUILDKIT=1 docker build . --build-arg BUILDKIT_INLINE_CACHE=1 --target builder --cache-from repo/image:builder --tag repo/image:builder
  3. push builder docker push repo/image:builder
  4. pull image docker pull repo/image:tag
  5. build image 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. push image 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

At COPY --from=builder --chown=nginx:nginx /app/frontend/built /project/web/public the docker build gets stuck forever(30-40 min after which I stop it manually) without error.

EDIT: At the first run, when images are not yet present in the registry, builder caching and COPY --from=builder works as expected. Only from the second build onwards does it get stuck at COPY --from=builder

-- Adnan Mujkanovic
docker
docker-in-docker
jenkins
kubernetes

1 Answer

4/9/2020

I don't know what the problem was but it seems that this tiborvass/docker:19.03.8-dind-bk1413 dind image is stable and runs without hanging forever.

https://github.com/moby/buildkit/issues/1430

-- Adnan Mujkanovic
Source: StackOverflow