Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure docker-compose.yml for Kafka local development?

I'm trying to setup Kafka in a docker container for local development. My docker-compose.yml looks as follows:

version: '3'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181"
    hostname: zookeeper
  kafka:
    image: wurstmeister/kafka
    command: [start-kafka.sh]
    ports:
      - "9092"
    hostname: kafka
    environment:
      KAFKA_CREATE_TOPICS: "UploadFile:1:1,GetFile:1:1,TrackUpload:1:1,GetEmailContent:1:1" # topic:partition:replicas
      KAFKA_ADVERTISED_HOST_NAME: kafka # docker-machine ip
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_PORT: 9092
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - "zookeeper"

Unfortunately my node app running on my localhost (not in docker) cannot connect to it. I used the url 'kafka:9092' and even 'localhost:9092'. Nothing works. Any idea what's happening?

like image 390
THpubs Avatar asked Aug 19 '18 16:08

THpubs


People also ask

Is Docker compose for local development?

Introduction to Docker ComposeYou can use Docker Compose to define your local development environment, including environment variables, ports you need accessible, and volumes to mount. Everything is defined in docker-compose.


1 Answers

Expose the host port 9092 for kafka service & you should be able to connect via "localhost:9092" from the app or host machine.

  ....
  kafka:
    image: wurstmeister/kafka
    command: [start-kafka.sh]
    ports:
      - "9092:9092"
  ....
like image 63
vivekyad4v Avatar answered Oct 04 '22 03:10

vivekyad4v