Debugging Spring Boot in Docker: Logs, Exec, and Remote Debug
Fast recall
Quick revision
Core answer
Practical container debugging skills — a common need in production incidents and day-to-day development
Having no structured logging (plain System.out.println) making log analysis impossible; or running without remote debug capability because it wasn't set up until the bug appeared
Show JAVA_TOOL_OPTIONS for enabling JDWP without modifying Dockerfile, explain how to take thread dumps from inside the container, and mention kubectl port-forward for Kubernetes debugging
Interview-ready guide
Interview answer
Debugging a Spring Boot container means choosing between three tools depending on what kind of problem you have: interactive log inspection for startup failures, remote JDWP debugging for code-level bugs, and ephemeral debug containers for filesystem and process issues.
Log inspection — first tool for startup failures
docker logsstreams logs in real time; add--follow --since 5mto limit to recent logs — the first tool you reach for on any startup failure or exception- If the container exits immediately, use
docker logswithout--followafter the fact — the logs are still available until the container is removed even though the process died - Spring Boot startup errors are almost always in the logs:
APPLICATION FAILED TO STARTwith a clear reason (missing property, bean conflict, database unreachable) — the error is one scroll up from the stack trace, not buried in it
JDWP remote debugging
- Add
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005to the JVM startup command and expose port 5005 with-p 5005:5005in Docker Compose — thesuspend=nstarts the application immediately without waiting for a debugger to attach - Never expose the JDWP port in production — the debug port has no authentication; anyone who can reach port 5005 can pause threads, read memory, and execute arbitrary code in the JVM
- Connect IntelliJ's remote debugger to
localhost:5005; set breakpoints normally — the debugger communicates with the JVM through the exposed port exactly as if debugging locally
Exec and ephemeral containers
docker exec -itopens a shell inside the running container for filesystem inspection, testing connectivity with/bin/sh wget, or checking environment variables — not available on distroless images- For distroless containers in Kubernetes, use
kubectl debug -itto attach an ephemeral sidecar with a shell without modifying the running pod--image=busybox --target=app docker statsshows CPU, memory, and network I/O in real time — the first tool for performance issues where the application is running but responding slowly
Debugging Spring Boot in Docker: Logs, Exec, and Remote Debug
Direct Answer
Primary debugging approaches: (1) check logs with docker logs -f, (2) exec into the container with docker exec -it for live inspection, (3) enable JVM remote debug port (5005) with -agentlib:jdwp and port-forward it to attach your IDE debugger. In Kubernetes use kubectl logs and kubectl exec equivalents.
Common Mistakes & Pitfalls
Having no structured logging (plain System.out.println) making log analysis impossible; or running without remote debug capability because it wasn't set up until the bug appeared
Check your understanding
Answer these without looking back at the article.
- How do you take a heap dump from a Spring Boot app running in a Docker container?
- What is the JAVA_TOOL_OPTIONS environment variable and how does it differ from JAVA_OPTS?
- How do you configure Spring Boot to output structured JSON logs?
Related interview prep categories
2Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.