title: Creating Kafka Topic with docker-compose
body: <p>I am starting my first docker proyect, trying to setup zookeeper and Kafka. <br /> <br />
  I have the following docker-compose.yml:</p>
  <pre><code>version: &quot;3.8&quot;
  
  networks:
      mynet:
  
  services:
  
    zookeeper:
      image: wurstmeister/zookeeper
      ports:
        - &quot;2181:2181&quot;
     networks:
        - mynet
        
    kafka:
      image: wurstmeister/kafka:2.12-2.4.0
      ports:
        - &quot;9092:9092&quot;
      expose:
        - &quot;9093&quot;
      environment:
        KAFKA_LISTENERS: INSIDE://0.0.0.0:9093,OUTSIDE://0.0.0.0:9092
        KAFKA_ADVERTISED_LISTENERS: INSIDE://kafka:9093,OUTSIDE://localhost:9092
        KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT
        KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE
        KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
        # Create a topic NAME:PARTITION:REPLICAS
        KAFKA_CREATE_TOPICS: &quot;example-topic:1:1&quot;
     networks:
        - mynet
        
    kafka-manager:
      image: sheepkiller/kafka-manager:latest
      environment:
        ZK_HOSTS: &quot;zookeeper:2181&quot;
      ports:
        - 9000:9000
      networks:
        - mynet
  </code></pre>
  <p>I execute the docker-compose.yml:
  <code>sudo docker-compose up -d</code></p>
  <p>To check if I have the topic created, I access the Kafka shell through:
  <code>sudo docker exec -it &lt;&lt;CONTAINER ID&gt;&gt; sh</code></p>
  <p>In this shell I go to:
  <code>cd opt/kafka</code></p>
  <p>And execute:
  <code> bin/kafka-topics.sh --list --zookeeper localhost:2181</code></p>
  <p>And the output is a timeout error:</p>
  <pre><code>Exception in thread &quot;main&quot; kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection while in state: CONNECTING
      at kafka.zookeeper.ZooKeeperClient.$anonfun$waitUntilConnected$3(ZooKeeperClient.scala:259)
      at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
      at kafka.utils.CoreUtils$.inLock(CoreUtils.scala:253)
      at kafka.zookeeper.ZooKeeperClient.waitUntilConnected(ZooKeeperClient.scala:255)
      at kafka.zookeeper.ZooKeeperClient.&lt;init&gt;(ZooKeeperClient.scala:113)
      at kafka.zk.KafkaZkClient$.apply(KafkaZkClient.scala:1858)
      at kafka.admin.TopicCommand$ZookeeperTopicService$.apply(TopicCommand.scala:321)
      at kafka.admin.TopicCommand$.main(TopicCommand.scala:54)
      at kafka.admin.TopicCommand.main(TopicCommand.scala)
  </code></pre>