FROM busyboxRUN echo'hello world'> /tmp/test
RUN exit 1 # problematic commandRUN echo'ready'
Simply remove the failing command and subsequent commands:
1
2
FROM busyboxRUN echo'hello world'> /tmp/test
2.2 Inspect Intermediate Layers
Turn off BuildKit to see layer SHA:
1
2
3
DOCKER_BUILDKIT=0 docker build -ttest.# Use the SHA of the last successful layer
docker run --rm-it <sha> sh
3. Interactive Debugging with nsenter
3.1 Basic nsenter Debugging
1
2
3
4
FROM busyboxRUN echo'hello world'RUN sleep infinite # Add this for debuggingRUN exit 1
1
2
3
4
5
6
7
# In terminal 1: Start the build
docker build -ttest.# In terminal 2: Enter the container's namespace
docker run -it--rm--privileged--pid=host justincormack/nsenter1
ps -ef | grep sleep
nsenter -p-m-u-i-n-t <PID> sh
3.2 Alternative nsenter Approach with Alpine
1
2
docker run --privileged--pid=host -it alpine \
nsenter -t 1 -m-u-n-i sh
# Build specific target
docker build -ttest--target working .# Debug the working stage
docker run --rm-ittest sh
4.2 Advanced Multi-stage Debugging
1
2
3
4
5
6
7
8
# Development stage with debugging toolsFROMruby:3.2asdevelopmentRUN apt-get update &&\
apt-get install-y vim curl htop
# Production stageFROMruby:3.2-slimasproductionCOPY --from=development /app /app