title: Cannot connect to single-node Kafka server through Docker
body: <p>I'm trying to connect to single-node Kafka server through Docker but I am getting the following error:</p>
  
  <pre><code>%3|1529395526.480|FAIL|rdkafka#producer-1| [thrd:localhost:9092/bootstrap]: localhost:9092/bootstrap: Connect to ipv4#127.0.0.1:9092 failed: Connection refused
  %3|1529395526.480|ERROR|rdkafka#producer-1| [thrd:localhost:9092/bootstrap]: localhost:9092/bootstrap: Connect to ipv4#127.0.0.1:9092 failed: Connection refused
  %3|1529395526.480|ERROR|rdkafka#producer-1| [thrd:localhost:9092/bootstrap]: 1/1 brokers are down
  </code></pre>
  
  <p>The docker-compose.yml file contents are as follows:</p>
  
  <pre><code>version: '2'
  services:
    zookeeper:
      image: confluentinc/cp-zookeeper:latest
      network_mode: host
      environment:
        ZOOKEEPER_CLIENT_PORT: 2181
        ZOOKEEPER_TICK_TIME: 2000
      extra_hosts:
        - "moby:127.0.0.1"
  
    kafka:
      image: confluentinc/cp-kafka:latest
      network_mode: host
      depends_on:
        - zookeeper
      environment:
        KAFKA_BROKER_ID: 1
        KAFKA_ZOOKEEPER_CONNECT: localhost:2181
        KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
        KAFKA_ADVERTISED_HOSTNAME: kafka
        KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      extra_hosts:
        - "moby:127.0.0.1"
  
    schema_registry:
      image: confluentinc/cp-schema-registry
      hostname: schema_registry
      depends_on:
        - zookeeper
        - kafka
      ports:
        - "8081:8081"
      environment:
        SCHEMA_REGISTRY_HOST_NAME: schema_registry
        SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: '127.0.0.1:2181'
  </code></pre>
  
  <p>The Dockerfile contents are the following:</p>
  
  <pre><code>FROM python:2
  
  WORKDIR /kafkaproducerapp
  
  COPY requirements.txt ./
  RUN pip install --no-cache-dir -r requirements.txt
  
  COPY . .
  
  CMD [ "python", "./BackOffice_Producer.py" ]
  </code></pre>
  
  <p>What am I doing wrong?</p>