1

I need to run intermediate image generated during docker build and debug why a step in my Dockerfile failed. But I found the sha256 hash printed by docker build command can't work as an image for docker run.

What should I do to get the correct hash to run the intermediate image generated during docker build?

Here's my docker file:

From ubuntu:14.04
RUN mkdir -p /test
# A step failed which I want to debug inside container, below is just an example
RUN apt-get aaabbbccc

I executed docker build --no-cache --rm=false --progress=plain -t test . in the directory of this docker file, and here's the output:

#1 [internal] load build definition from Dockerfile
#1 sha256:4ddf269e3dcad450ffd58539a6a1bef5fcdbd2658a967686117ef97577644054
#1 transferring dockerfile: 38B done
#1 DONE 0.1s

#2 [internal] load .dockerignore
#2 sha256:8bdc29cab8a002907b181b561346e3bfff86f15af8dbf1e71734a04dbfe84722
#2 transferring context: 2B done
#2 DONE 0.1s

#3 [internal] load metadata for docker.io/library/ubuntu:14.04
#3 sha256:38a6494a6a0d960a5a01b6b8e3ed8ef4f5117f0d5ffa89b529a2860d9846ad70
#3 DONE 0.0s

#4 [1/3] FROM docker.io/library/ubuntu:14.04
#4 sha256:a9ab970ef4810de5fde05a4caa66b977b639ff067a8b0241cb81432a2f533c04
#4 CACHED

#5 [2/3] RUN mkdir -p /test
#5 sha256:fa1edf28f7de30d57aa7e51d18feabe4f0c42ba43743ab7363364f49707871b0
#5 DONE 0.6s

#6 [3/3] RUN apt-get aaabbbccc
#6 sha256:3fcc9acaf5ccb3a9773f84dae10ea1a4bd6906b27d3138756542c41f8344ea4f
#6 0.534 E: Invalid operation aaabbbccc
#6 ERROR: executor failed running [/bin/sh -c apt-get aaabbbccc]: exit code: 100
------
 > [3/3] RUN apt-get aaabbbccc:
------
executor failed running [/bin/sh -c apt-get aaabbbccc]: exit code: 100

I suppose the "sha256:fa1edf28f7de30d57aa7e51d18feabe4f0c42ba43743ab7363364f49707871b0" should be the hash of intermediate image generated by first 2 steps of the build process, but when I tried to execute docker run --rm -it fa1edf28f7de30d57aa7e51d18feabe4f0c42ba43743ab7363364f49707871b0, docker tells me that there's no such image.

docker: Error response from daemon: No such image: sha256:fa1edf28f7de30d57aa7e51d18feabe4f0c42ba43743ab7363364f49707871b0.
See 'docker run --help'.

Docker version: Docker version 20.10.17, build 100c701

System version: Ubuntu 20.04.4 LTS (on WSL2)

junshi356
  • 13
  • 4
  • That doesn't appear to be possible with the newer BuildKit backend. In addition to editing the Dockerfile as the linked question suggests, [this answer](https://stackoverflow.com/a/66770818) also suggests setting an environment variable `DOCKER_BUILDKIT=0` to (temporarily) disable BuildKit, so you will get the intermediate images available for debugging. – David Maze Aug 15 '22 at 11:01

0 Answers0