title: how to access kafka installed in docker with golang on host
body: <p>I need to use golang to access kafka,so i installed a kafka &amp; zookepper in docker.</p>
  
  <p>1.here is kafka install script:</p>
  
  <pre><code># pull images
  docker pull wurstmeister/zookeeper 
  docker pull wurstmeister/kafka
  
  # run kafka &amp; zookepper
  docker run -d --name zookeeper -p 2181 -t wurstmeister/zookeeper  
  docker run --name kafka -e HOST_IP=localhost -e KAFKA_ADVERTISED_PORT=9092 -e KAFKA_BROKER_ID=1 -e ZK=zk -p 9092:9092 --link zookeeper:zk -t wurstmeister/kafka  
  
  # enter container
  docker exec -it ${CONTAINER ID} /bin/bash  
  cd opt/kafka_2.11-0.10.1.1/ 
  
  # make a tpoic
  bin/kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic mykafka 
  
  # start a producer in terminal-1
  bin/kafka-console-producer.sh --broker-list localhost:9092 --topic mykafka 
  
  # start another terminal-2 and start a consumer
  bin/kafka-console-consumer.sh --zookeeper zookeeper:2181 --topic mykafka --from-beginning 
  </code></pre>
  
  <p>when i type some message in producer, the consumer will get it immediately.
  so i assumed that the kafka is working fine</p>
  
  <p>2.Now i need to create a consumer with golang to access kafka.</p>
  
  <p>here is my golang demo code:</p>
  
  <pre><code>import "github.com/bsm/sarama-cluster"
  func Consumer(){
      // init (custom) config, enable errors and notifications
      config := cluster.NewConfig()
      config.Consumer.Return.Errors = true
      config.Group.Return.Notifications = true
  
      // init consumer
      brokers := []string{"192.168.9.100:9092"}
      topics := []string{"mykafka"}
      consumer, err := cluster.NewConsumer(brokers, "my-group-id", topics, config)
      if err != nil {
          panic(err)
      }
      defer consumer.Close()
  
      // trap SIGINT to trigger a shutdown.
      signals := make(chan os.Signal, 1)
      signal.Notify(signals, os.Interrupt)
  
      // consume messages, watch errors and notifications
      for {
          select {
          case msg, more := &lt;-consumer.Messages():
              if more {
                  fmt.Fprintf(os.Stdout, "%s/%d/%d\t%s\t%s\n", msg.Topic, msg.Partition, msg.Offset, msg.Key, msg.Value)
                  consumer.MarkOffset(msg, "")    // mark message as processed
              }
          case err, more := &lt;-consumer.Errors():
              if more {
                  log.Printf("Error: %s\n", err.Error())
              }
          case ntf, more := &lt;-consumer.Notifications():
              if more {
                  log.Printf("Rebalanced: %+v\n", ntf)
              }
          case &lt;-signals:
              return
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>actually this demo code is copied from a github repo's demo:<a href="https://github.com/bsm/sarama-cluster" rel="nofollow noreferrer">sarama-cluster</a> </p>
  
  <p>When running the code, i got an error:</p>
  
  <pre><code>kafka: client has run out of available brokers to talk to (Is your cluster reachable?)
  </code></pre>
  
  <p>i did use a port map when start kafka,but just can't access it in golang</p>
  
  <p>is there a way to use curl to access kafka?
  i'v tried: </p>
  
  <pre><code>curl http://192.168.99.10:9092
  </code></pre>
  
  <p>and kafka report an error:</p>
  
  <pre><code>[2017-08-02 06:39:15,232] WARN Unexpected error from /192.168.99.1; closing connection (org.apache.kafka.common.network.Selector)
  org.apache.kafka.common.network.InvalidReceiveException: Invalid receive (size = 1195725856 larger than 104857600)
      at org.apache.kafka.common.network.NetworkReceive.readFromReadableChannel(NetworkReceive.java:95)
      at org.apache.kafka.common.network.NetworkReceive.readFrom(NetworkReceive.java:75)
      at org.apache.kafka.common.network.KafkaChannel.receive(KafkaChannel.java:203)
      at org.apache.kafka.common.network.KafkaChannel.read(KafkaChannel.java:167)
      at org.apache.kafka.common.network.Selector.pollSelectionKeys(Selector.java:379)
      at org.apache.kafka.common.network.Selector.poll(Selector.java:326)
      at kafka.network.Processor.poll(SocketServer.scala:499)
      at kafka.network.Processor.run(SocketServer.scala:435)
      at java.lang.Thread.run(Thread.java:748)
  </code></pre>
  
  <p>BTW:</p>
  
  <p>i use windows 7</p>
  
  <p>dcoker machine's ip :192.168.99.100</p>
  
  <p>it's drived me crazy</p>
  
  <p>Is there some advice or solution? appreciate!!!</p>