This is my docker-compose.yml file.
version: '2'
networks:
kafkanet:
driver: bridge
services:
zookeeper:
image: 'bitnami/zookeeper:latest'
ports:
- '2181:2181'
environment:
- ALLOW_ANONYMOUS_LOGIN=yes
networks:
- kafkanet
kafka:
image: 'bitnami/kafka:latest'
networks:
- kafkanet
ports:
- '9093:9093'
environment:
- KAFKA_BROKER_ID=1
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT
- KAFKA_CFG_LISTENERS=CLIENT://:9092,EXTERNAL://:9093
- KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://kafka:9092,EXTERNAL://localhost:9093
- KAFKA_CFG_INTER_BROKER_LISTENER_NAME=CLIENT
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
- ALLOW_PLAINTEXT_LISTENER=yes
depends_on:
- zookeeper
spring_boot:
build: .
networks:
- kafkanet
depends_on:
- kafka
- zookeeper
Now, after I run docker-compose up -d, kafka works fine. If I set spring.kafka.bootstrap-servers = 0.0.0.0:9093 and run the spring app locally in my IDE, it works fine, too. But in docker, the spring_boot container can't connect with kafka.
I searched similar questions and some people said spring.kafka.bootstrap-servers = kafka:9092 should be used, but there will be errors when build the docker image with this setting.
Thanks for any help.
Dockerfile
FROM openjdk:11
VOLUME /tmp
COPY target/*.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]