When building a docker image, and there is a failure, can I have it run a bash shell in docker image?

So trying to word this well

If I am doing a “docker build …” and one of my steps hits an error. It jumps back out to my host OS terminal.

What I’d really love, is at that point where it hit a failure, is to have it run a bash shell. So I can debug a bit easier at why it is failing.

Right now, what I do when it happens, is fire up my base image from the start and run a bash shell

Then I manually cut and paste each line in from my Dockerfile, until it gets up to the point it failed, then I can debug.

But I’d really love it if I could, on error, to bring up a bash shell in that docker image, , so I can debug right from there.

Anyway to do this?

Image build is a non-iteractive batch operation, thus there is no way to get a debug shell during builds.

By default, each successfully layer will result in an intermediate image. You should find it in your local image cache (unless you use --force-rm). Just start a container from that image and go from there.

Note: for debugging purposes it is often useful to override the command from the ENTRYPOINT instruction by adding the option --entrypoint /bin/sh to your docker run command. You will get a clean shell, regardless of the ENTRYPOINT and/or CMD instruction in the Dockerfile.

Thanks, I was thinking that was the case.
Yeah, I can always hit my local cache of the image, its just sometimes a pain to find the right one if I don’t keep tidy and have lots of things going on at once.

So, for a summary, for all our friendly folks that may be interested in how I am accomplishing what I wanted in my description above?

I run docker images and find the image that my build left off on. and then I run
docker run --rm -it f8ac119d2739 /bin/bash
Where f8ac119d2739 was my image ID where it left off