title: kafka: cannot produce messages to kafka inside docker
body: <p>docker-compose.yml (<a href="https://github.com/wurstmeister/kafka-docker" rel="nofollow noreferrer">https://github.com/wurstmeister/kafka-docker</a>)</p>
  
  <pre><code>version: "2.1"
  services:
    zookeeper:
      image: wurstmeister/zookeeper
      ports:
        - "2181:2181"
    kafka:
      image: wurstmeister/kafka
      ports:
        - "9092:9092"
      environment:
        KAFKA_ADVERTISED_HOST_NAME: localhost
        KAFKA_ADVERTISED_PORT: 9092
        KAFKA_CREATE_TOPICS: "test:3:1"
        KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock
  </code></pre>
  
  <p>Errors when trying to produce messages following <a href="https://kafka.apache.org/quickstart" rel="nofollow noreferrer">https://kafka.apache.org/quickstart</a>:</p>
  
  <pre><code>~/kafka_2.11-1.0.0$ bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
  &gt;gh 
  &gt;[2018-01-19 17:28:15,385] ERROR Error when sending message to topic test with key: null, value: 2 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
  org.apache.kafka.common.errors.TimeoutException: Expiring 1 record(s) for test-0: 1566 ms has passed since batch creation plus linger time
  </code></pre>
  
  <p>list topics:</p>
  
  <pre><code>~/kafka_2.11-1.0.0$ bin/kafka-topics.sh --list --zookeeper localhost:2181
  __consumer_offsets
  test
  </code></pre>
  
  <p>why? thanks</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>how to set <code>KAFKA_ADVERTISED_HOST_NAME</code> or network to make my python/java program or kafka-console-producer.sh (outside docker container) to produce messages to the kafka by <code>localhost:9092</code>?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>It seems that the following docker-compose.yml working fine</p>
  
  <pre><code>version: "2"
  
  services:
    zookeeper:
      image: "wurstmeister/zookeeper:latest"
      network_mode: "host"
      ports:
        - 2181:2181
    kafkaserver:
      image: "wurstmeister/kafka:latest"
      network_mode: "host"
      ports:
        - 9092:9092
      environment:
        KAFKA_CREATE_TOPICS: "test:3:1"
        KAFKA_ZOOKEEPER_CONNECT: localhost:2181
  </code></pre>