Skip to content

Docker container for a single node Kafka broker

authorjapps edited this page Dec 25, 2018 · 14 revisions

Docker compose file

See here the docker-compose file

How to run the compose file

  • Go to the zerocode-docker-factory/compose dir in a terminal window

  • Then run

    • $ docker-compose -f kafka-single-node.yml up -d

    or

    • $ docker-compose -f kafka-single-node.yml up

This brings up both Zookeeper and Kafka server(server and broker mean the same thing on this page)

How to check the status of Kafka and Zookeeper?

$ docker ps
CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS              PORTS                          NAMES
9b5001dc2931        confluentinc/cp-kafka:5.0.1       "/etc/confluent/dock…"   3 hours ago         Up 3 hours          0.0.0.0:9092->9092/tcp         compose_kafka_1
037afbb001ac        confluentinc/cp-zookeeper:5.0.1   "/etc/confluent/dock…"   3 hours ago         Up 3 hours          2181/tcp, 2888/tcp, 3888/tcp   compose_zookeeper_1
$ 

Note-
See under the "NAMES" column(right hand ride) above, for `compose_kafka_1` as container name
and the "PORT" column to see which port it is listening to for the external clients

How to verify the port has been exposed outside docker container ?

  • To make sure Kafka broker is running and it has exposed the port 9092 to external client outside the docker,
    • nc -vz localhost 9092

$ nc -vz localhost 9092   
found 0 associations
found 1 connections:
     1: flags=82<CONNECTED,PREFERRED>
        outif lo0
        src ::1 port 51288
        dst ::1 port 9092
        rank info not available
        TCP aux info available

Connection to localhost port 9092 [tcp/XmlIpcRegSvc] succeeded!

Note- If a port is not exposed, you get the following message.
--------------------------------------------------------------
$ nc -vz localhost 9093  
nc: connectx to localhost port 9093 (tcp) failed: Connection refused
nc: connectx to localhost port 9093 (tcp) failed: Connection refused
$ 

How to verify that a message can be produced to and consume from a topic?

docker exec -it compose_kafka_1 bash