On my VPS I have 3 docker containers: zookeeper, kafka and my own java/spring boot service. My questions are:
- How should I configure kafka in compose file to be able to produce/consume messages both from the java service running as a docker container on the same VPS and from my local laptop?
- What kafka URL should I use in java service deployed to VPS (I tried 'localhost:29092' and 'kafka:29092' but with no luck - host not resorvable error)?
- What kafka URL should I use if I want to access it from my local laptop (I tried 'MY_VPS_IP_ADDRESS:29092' but I'm getting: 'LEADER_NOT_AVAILABLE')?
My docker compose file:
version: '3'
services:
zookeeper:
image: confluentinc/cp-zookeeper
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
kafka:
image: confluentinc/cp-kafka
container_name: kafka
ports:
- "29092:29092"
environment:
KAFKA_LISTENERS: INSIDE://0.0.0.0:9092,OUTSIDE://0.0.0.0:29092
KAFKA_ADVERTISED_LISTENERS: INSIDE://kafka:9092,OUTSIDE://MY_VPS_IP_ADDRESS:29092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
depends_on:
- zookeeper
I did also try wurstmeister version of these images but with the same result.