title: Cannot connect to Kafka Docker-container from other container: Connection refused - 1/1 brokers are down
body: <p>I am trying to hook up a data-aggregator to a kafka-broker The intent is to collect data from a HTTP Endpoint, and save that to a database periodically. Both are run in docker, using the following docker-compose.yml:</p>
  
  <pre><code>version: "3"
  
  services:
    zk:
      image: confluentinc/cp-zookeeper:5.0.0
      container_name: zk
      ports:
        - 2181:2181
      environment:
        ZOOKEEPER_CLIENT_PORT: 2181
        ZOOKEEPER_TICK_TIME: 2000
      restart: on-failure:5
    kafka:
      image: confluentinc/cp-kafka:5.0.0
      container_name: kafka
      ports:
        - 9092:9092
        - 9094:9094
      environment:
        KAFKA_ZOOKEEPER_CONNECT: zk:2181
        KAFKA_ADVERTISED_LISTENERS: INSIDE://kafka:9092,OUTSIDE://localhost:9094
        KAFKA_LISTENERS: INSIDE://0.0.0.0:9092,OUTSIDE://0.0.0.0:9094
        KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT
        KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE
        KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
        KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
        KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
        KAFKA_NUM_PARTITIONS: 4
      restart: on-failure:5
    tinygator-metric-aggregator:
      image: tinygator.aggregator:latest
      container_name: tg-aggregator
      environment:
        KAFKA_BOOTSTRAP_SERVER: localhost:9094
        KAFKA_TOPIC: test
        METRIC_ENDPOINT: "http://localhost:15672/api/queues/%2F/Test?sort=message_stats.publish_details.rate&amp;sort_reverse=true&amp;columns=name,message_stats.publish_details.rate,message_stats.deliver_get_details.rate"
        METRIC_METHOD: GET
        METRIC_INTERVAL: 5000
        METRIC_HEADERS: '{"authorization":"Basic Z3Vlc3Q6Z3Vlc3Q="}'
      restart: on-failure:5
  </code></pre>
  
  <p>Kafka and zk seem to start normally. However, I get the following error for the aggregator:</p>
  
  <pre><code>tg-aggregator                  | %3|1576348274.043|FAIL|rdkafka#producer-1| [thrd:0.0.0.0:9094/bootstrap]: 0.0.0.0:9094/bootstrap: Connect to ipv4#0.0.0.0:9094 failed: Connection refused (after 4704ms in state CONNECT)
  tg-aggregator                  | %3|1576348274.048|ERROR|rdkafka#producer-1| [thrd:0.0.0.0:9094/bootstrap]: 0.0.0.0:9094/bootstrap: Connect to ipv4#0.0.0.0:9094 failed: Connection refused (after 4704ms in state CONNECT)
  tg-aggregator                  | %3|1576348274.048|ERROR|rdkafka#producer-1| [thrd:0.0.0.0:9094/bootstrap]: 1/1 brokers are down
  tg-aggregator                  | Unhandled exception. System.Net.Http.HttpRequestException: Cannot assign requested address
  tg-aggregator                  |  ---&gt; System.Net.Sockets.SocketException (99): Cannot assign requested address
  tg-aggregator                  |    at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
  tg-aggregator                  |    --- End of inner exception stack trace ---
  tg-aggregator                  |    at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
  tg-aggregator                  |    at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
  tg-aggregator                  |    at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  tg-aggregator                  |    at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  tg-aggregator                  |    at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
  tg-aggregator                  |    at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  tg-aggregator                  |    at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
  tg-aggregator                  |    at MetricAggregator.Program.Main(String[] args) in /app/Program.cs:line 83
  tg-aggregator                  |    at MetricAggregator.Program.&lt;Main&gt;(String[] args)
  </code></pre>
  
  <p>Now, me and a colleague have been sitting on this for hours now (we are both super new to Kafka). The issue does not occur for the guy who has written the aggregator (can be found under <a href="https://github.com/Azer0s/TinyGator" rel="nofollow noreferrer">https://github.com/Azer0s/TinyGator</a>) on MacOS. I am on Windows 10, my colleague is on Arch. We have tried a lot of different port numbers, ways to set the Kafka listeners and advertised listeners, etc. In short, we are at a complete loss.</p>
  
  <p>Does anyone have an idea?</p>
  
  <p>UPDATE:</p>
  
  <p>After reading up on Kafka listeners, I have now modified my docker-compose, changing the address on which the aggregator is trying to connect:</p>
  
  <pre><code>KAFKA_BOOTSTRAP_SERVER: kafka:9092
  </code></pre>
  
  <p>But error is still the same. </p>