Advanced Docker Buildx Debugging Guide: Using --on-error
The --on-error flag in Docker Buildx is a powerful debugging feature that allows you to inspect the build container's state when a build step fails. This is
Advanced Docker Buildx Debugging Guide: Using –on-error
Introduction to Buildx –on-error
The --on-error flag in Docker Buildx is a powerful debugging feature that allows you to inspect the build container’s state when a build step fails. This is particularly useful for:
Investigating build failures in complex Dockerfiles
Debugging package installation issues
Troubleshooting configuration problems
Examining file system state at the point of failure
Basic Usage
1. Simple Example with –on-error
1
2
3
4
FROM ubuntu:22.04RUN apt-get update
RUN apt-get install-y nonexistent-package
RUN echo"This won't run due to previous error"
FROMgolang:1.20ASbuilderWORKDIR /appCOPY go.* ./RUN go mod download
COPY . .RUN go build -v# If this failsFROM alpine:3.18COPY --from=builder /app/myapp /usr/local/bin/
# Maximum verbosity
docker buildx build \--progress=plain \--on-error=continue\--no-cache\--build-argBUILDKIT_STEP_LOG_MAX_SIZE=-1\--build-argBUILDKIT_STEP_LOG_MAX_SPEED=-1.
3. Debug Environment Setup
1
2
3
4
5
6
7
8
9
# Add debugging tools in your DockerfileRUN apt-get update && apt-get install-y\
vim \
curl \
netcat \
strace \
tcpdump
# Use these in your debug session