intermediateSpring Boot Integration: Dockerizing, PostgreSQL, Redis, Kafka & Microservices

What is the classic Kafka-in-Docker connectivity bug, and how do you fix it?

A broker can be configured to advertise localhost:9092 as its address to clients. Within the broker's own container, that's technically true, but any other container trying to use that advertised address to connect will be pointed back at itself, not the broker — connections fail after an initially successful metadata request. The fix is setting KAFKA_ADVERTISED_LISTENERS to the broker's actual reachable network alias (its Compose/Kubernetes service name), not localhost.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What's the difference between Actuator's readiness and liveness probes, and why does the distinction matter?← Back to all Docker questions