Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I attach to intermediate docker container when building with buildkit

I recently heard about Buildkit and have been trying to use it with Docker.

I'm using DOCKER_BUILDKIT=1 docker build . -t experimental to build my Dockerfile.

My Dockerfile doesn't build properly because of some missing dependant packages.

What I want to do is to attach to the last working intermediate container and fix the problem with say, apt tools.

When building without Buildkit, this would have been possible with the hash values of intermediate containers from the terminal output.

However, the output from Buildkit is not providing me such values. So, is there any way for me to access them?

Thanks in advance.

like image 763
Jinu Avatar asked Mar 30 '20 04:03

Jinu


People also ask

How do I use docker BuildKit?

There are two parts to using BuildKit: enabling it in a specific build, and choosing the “frontend” to use in your Dockerfile . Note that I'm assuming you're using Docker 19.03 or later. If you just want the short version: Set the DOCKER_BUILDKIT environment variable to 1 .

How do multistage docker builds work?

With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don't want in the final image.

How do I enable BuildKit docker?

To enable BuildKit builds Easiest way from a fresh install of docker is to set the DOCKER_BUILDKIT=1 environment variable when invoking the docker build command, such as: $ DOCKER_BUILDKIT=1 docker build .


1 Answers

I think it is not possible at the moment see buildkit/issue#1053.

But BuildKit still caches all layers so you could use a work around.

  • Inspecting the image before the failing RUN command, comment out the failing and all subsequent RUN commands. Rerun docker build and then do docker run to inspect the image.

  • Inspecting the image after the failing RUN command, add || true at the end of your RUN command to force the command to succeed. Rerun docker build and then do docker run to inspect the image.

like image 118
Moritz Avatar answered Oct 11 '22 12:10

Moritz