title: How to run mulitple Kafka brokers using docker-compose?
body: <p>I am trying to run multiple Kafka brokers with docker-compose. I am going to use it both in Docker network and on local machine, that's why I am using different ports for brokers:</p>
  <pre class="lang-yaml prettyprint-override"><code>version: '3'
  
  services:
    zookeeper_local_dev:
      image: wurstmeister/zookeeper
      container_name: zookeeper_local_dev
      ports:
        - &quot;2181:2181&quot;
    kafka_local_dev_1:
      image: wurstmeister/kafka
      hostname: kafka
      ports:
        - &quot;9092:9092&quot;
      environment:
        KAFKA_BROKER_ID: 1
        KAFKA_ADVERTISED_PORT: 9092
        KAFKA_ADVERTISED_HOST_NAME: kafka
        KAFKA_ZOOKEEPER_CONNECT: zookeeper_local_dev:2181
        KAFKA_LISTENERS: INTERNAL://kafka:9092
        KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:9092
        KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT
        KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
      depends_on:
        - zookeeper_local_dev
    kafka_local_dev_2:
      image: wurstmeister/kafka
      hostname: kafka
      ports:
        - &quot;9093:9093&quot;
      environment:
        KAFKA_BROKER_ID: 2
        KAFKA_ADVERTISED_PORT: 9093
        KAFKA_ADVERTISED_HOST_NAME: kafka2
        KAFKA_ZOOKEEPER_CONNECT: zookeeper_local_dev:2181
        KAFKA_LISTENERS: INTERNAL://kafka2:9093
        KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka2:9093
        KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT
        KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
      depends_on:
        - zookeeper_local_dev
  </code></pre>
  <p>I am getting an error for the second broker when it's started:</p>
  <p><code>org.apache.kafka.common.KafkaException: Socket server failed to bind to kafka2:9093: Unresolved address.</code></p>
  <p>Could anybody assist?</p>