In spring application properties localhost
refers to application's container, which need to point to the kafka container:
spring:
kafka:
consumer:
bootstrap-servers: kafka:9092
...
producer:
bootstrap-servers: kafka:9092
I usually prefer confluent's Kafka docker-compose, though.