Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to connect to wurstmeister/kafka

I am running wurstmeister/kafka in a ubuntu 14.04 LTS machine. Kafka container is running fine. However I am not able to connect my microservice to this container.

Kafka docker-compose.yml:

version: '2'
services:
  zookeeper:
    image: user1/zookeeper:3.4.9
    ports:
      - "2181:2181"
  kafka:
    image: my-kafka
    ports:
      - "9092:9092"
    hostname: kafka-01
    environment:
      KAFKA_ADVERTISED_PORT: 9092
      KAFKA_ADVERTISED_HOST_NAME: "kafka-01"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_CREATE_TOPICS: "topic1:1:1,topic2:1:1"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

docker-compose for microservice(myapp):

version: '2'

services:
  myapp:
    network_mode: 'bridge'
    extends:
      file: myapp.base.yml
      service: myapp
    links:
      - kafka

  zookeeper:
    network_mode: 'bridge'
    extends:
      file: zookeeper.yml
      service: zookeeper

  kafka:
    network_mode: 'bridge'
    extends:
      file: kafka.yml
      service: kafka
    links:
      - zookeeper

I have linked kafka in an env:

kafkaHost=kafka-01:9092

Please let me know what am I doing wrong or if more info is required. Thanks in advance.

like image 316
humblebee Avatar asked Oct 30 '16 15:10

humblebee


Video Answer


1 Answers

The hostname should be what you specified in "links", ie. "kafka". As @dnephin said the hostname is not needed. I think what you want is actually KAFKA_ADVERTISED_HOST_NAME environment variable.

What version of docker do you have? I am using docker 1.12.3 on Mac OS with no issues.

You might also want to try the Confluent docker images:

  • https://hub.docker.com/r/confluentinc/cp-kafka/
  • https://hub.docker.com/r/confluentinc/cp-zookeeper/

Here's my sample docker compose file:

version: "2"
services:
  web:
    image: nginx:latest
    links: 
      - kafka
  zookeeper:
    extends:
      file: kafka-services.yml
      service: zookeeper
  kafka:
    extends:
      file: kafka-services.yml
      service: kafka
    depends_on:
      - zookeeper

My base kafka services compose file (kafka-services.yml):

version: '2'
services:
  zookeeper:
    image: confluentinc/cp-zookeeper:latest
    ports:
      - "32181:32181"
    environment:
      ZOOKEEPER_CLIENT_PORT: 32181
      ZOOKEEPER_TICK_TIME: 2000

  kafka:
    image: confluentinc/cp-kafka:latest
    ports:
     - "29092:29092"
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:32181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092
like image 66
coughman Avatar answered Oct 19 '22 02:10

coughman