Sometimes it’s useful to inspect the filesystem of the step that failed, not just the last good step. I’ve written a guide on how to debug docker builds like that. In short, look at the container ID of the failed step, then commit that to a temporary image, then run ‘sh’ (or ‘env’ or whatever) from that temporary image.
docker commit d590aa9618dc mytempimage
docker run -ti --rm mytempimage sh