Here's a working docker-compose that runs zookeeper, kafka and kafka-ui in same network.
version: '3.8'
services:
zookeeper:
container_name: zookeeper
image: confluentinc/cp-zookeeper:latest
hostname: zookeeper
restart: always
environment:
ZOOKEEPER_SERVER_ID: 1
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ports:
- 2181:2181
kafka:
container_name: kafka
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper
restart: always
environment:
KAFKA_BROKER_ID: 1
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092,RMOFF_DOCKER_HACK://kafka:9093
KAFKA_LISTENERS: PLAINTEXT://:9092,RMOFF_DOCKER_HACK://:9093
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,RMOFF_DOCKER_HACK:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: RMOFF_DOCKER_HACK
ports:
- 9092:9092
kouncil:
container_name: kouncil
image: consdata/kouncil:latest
restart: always
depends_on:
- kafka
environment:
bootstrapServers: kafka:9093
BOOTSTRAPSERVERS: kafka:9093
BOOTSTRAP_SERVERS: kafka:9093
ports:
- 8888:8080