in Education by
Question I am trying to run a single Kafka instance in docker. I can create topics but cannot consume from or produce to them. When I try my Kafka broker logs an error message. kafka_1 | [2019-03-24 16:45:05,263] ERROR [KafkaApi-5] Number of alive brokers '0' does not meet the required replication factor '1' for the offsets topic (configured via 'offsets.topic.replication.factor'). This error can be ignored if the cluster is starting up and not all brokers are up yet. (kafka.server.KafkaApis) I don't understand the Number of alive brokers '0' bit as it is a Kafka broker that is logging this so surely there must be at least one broker (itself)? I am using the default server.properties file with the following changes: listeners=PLAINTEXT://0.0.0.0:9092 advertised.listeners=PLAINTEXT://192.168.0.109:9092 zookeeper.connect=zookeeper:2181 where 192.168.0.109 is my host machine IP. Files docker-compose version: '3.4' services: zookeeper: build: context: ./ dockerfile: zookeeper.dockerfile network: host image: zookeeper ports: - "2181:2181" kafka: build: context: ./ dockerfile: kafka.dockerfile network: host image: kafka ports: - "9092:9092" kafka.dockerfile FROM alpine:3.7 # Set the name for a non-priliaged user ENV APPUSER=appuser # Install dependnacies RUN apk add bash RUN apk add openjdk8-jre # Add a non-privilaged user and change into it's home directory RUN adduser -D $APPUSER WORKDIR /home/$APPUSER # Download kafka and set its owner to $APPUSER RUN wget https://www-eu.apache.org/dist/kafka/2.1.0/kafka_2.11-2.1.0.tgz RUN chown $APPUSER kafka_2.11-2.1.0.tgz # Change to the non-privilaged user USER $APPUSER # Extract kafka RUN tar -xzf kafka_2.11-2.1.0.tgz # copy custom server.properties into image COPY ./server.properties ./ # Set working directory to kafka dir WORKDIR /home/$APPUSER/kafka_2.11-2.1.0 # start kafka with customer server.properties file CMD ["bin/kafka-server-start.sh", "../server.properties"] zookeeper.dockerfile FROM alpine:3.7 # Set the name for a non-priliaged user ENV APPUSER=appuser # Install dependnacies RUN apk add bash RUN apk add openjdk8-jre # Add a non-privilaged user and change into it's home directory RUN adduser -D $APPUSER WORKDIR /home/$APPUSER # Download kafka and set its owner to $APPUSER RUN wget https://www-eu.apache.org/dist/kafka/2.1.0/kafka_2.11-2.1.0.tgz RUN chown $APPUSER kafka_2.11-2.1.0.tgz # Change to the non-privilaged user USER $APPUSER # Extract kafka RUN tar -xzf kafka_2.11-2.1.0.tgz # Set working directory to kafka dir WORKDIR /home/$APPUSER/kafka_2.11-2.1.0 # Run zookeeper CMD ["bin/zookeeper-server-start.sh", "config/zookeeper.properties"] JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
This is down to the listeners configuration. When you specify advertised.listeners=PLAINTEXT://192.168.0.109:9092 then Kafka will try to connect to 192.168.0.109 from within the Docker container. But if this is a host address, and if you've not set up the appropriate Docker networking wizardry, it will fail. When you specify advertised.listeners=PLAINTEXT://localhost:9092 then Kafka will connect to localhost within the Docker container, which of course resolves to itself. The catch here is that you would be unable to use a Kafka client outside of the Docker container (either on your host machine, or another Docker container) because they would try to connect to localhost—locally to themselves on which there would not be a Kafka broker. This article explains in more detail the issue, and appropriate configuration to use. If you want a pre-built example of Kafka in Docker then this Docker Compose shows it.

Related questions

0 votes
    I'm trying to deploy a Docker container image to AWS using ECS, but the EC2 instance is not being created. I have ... , to begin with!! Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I am unable to find the containers under the directory: /var/lib/docker/containers Can you please tell me the ... the host machine? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    Kafka cluster can enforce quota on requests to control the broker resources used by clients. (1)False (2)True...
asked Jun 16, 2021 in Technology by JackTerrance
0 votes
    So I am trying to build a docker image with the Golang SDK, everything runs except the section in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I have tried to build a docker image based on mono to serve a docfx documentation. Here is my ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
0 votes
    So I have a Nginx running inside a docker container, I have a mysql running on the host system, I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Does containerization affect a programming language being compiled/interpreted ? Eg: Python is interpreted. C is ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Now that links are deprecated in docker-compose.yml (and were able to use the new networking feature to ... docker-compose.yml? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a dump.sql file that I would like to load with docker-compose. docker-compose.yml: services: postgres: ... how to do this? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a dump.sql file that I would like to load with docker-compose. docker-compose.yml: services: postgres: ... how to do this? Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    I'm looking for a way to configure Nginx to access hosted services through a subdomain of my server. Those services ... me with this? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Suppose you have two services on your topology API Web Interface Both supposed to be running on port 80. On docker ... to solve this? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Do I need to use separate Docker containers for my complex web application or I can put all required services in ... in one container? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I've been using K8S ConfigMap and Secret to manage our properties. My design is pretty simple, that keeps ... 't been created Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Can someone help me to differentiate between DevOps and Docker? Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
...