docker Posts

Monitoring Kafka Topics with Dockerized Kafka Manager

Yesterday, Dimas (one of my colleague), are asking me on how to monitor Kafka which are running on top of Openshift using a tools which are accessible thru browser.

One of the tools im recommending is Kafka Manager, which we can download from below url,

Lets start from the beginning, from how to start Zookeeper, Kafka Server, until simulate a simple produce and consume and monitoring it using Kafka Manager.

First, download Kafka from Apache site, extract it, and open bin folder. We need Zookeeper to start before we start anything else. Fyi for this example im using Win10 as my primary Operating System, so all my command below can be different depends on what Operating System you are using.

cd D:\software\kafka_2.13-2.4.0\bin\windows
zookeeper-server-start.bat ..\..\config\

And run Kafka Server afterwards,

kafka-server-start.bat ..\..\config\

Create a topic,

kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic my-testing-topic

Try produce a simple echo message using Kafka Producer,

kafka-console-producer.bat --broker-list localhost:9092 --topic my-testing-topic

And listen to the sent message using Kafka Consumer,

kafka-console-consumer.bat --bootstrap-server localhost:9092 -topic  my-testing-topic --from-beginning

If you only want to get all the new message, ignoring the old one, just remove “–from-beginning” parameter. And use “–offset” parameter to get a specific offset.

Next is running my Kafka Manager using Docker command. Fyi, is my laptop ip.

docker run --network host --add-host=moby: --add-host DESKTOP: -p 9000:9000 -e ZK_HOSTS=""  kafkamanager/kafka-manager

After Kafka-Manager is successfully started, we can browse our Kafka by opening thru browser,


Dockerfile for Creating A UBI-based Docker Image and OpenJDK

I use UBI 8 as base images for basically almost every java deployment. It’s lightweight, freely redistributable, and easy to configure.

This is my simplified Dockerfile script, which consist of UBI8 and OpenJDK installation.


MAINTAINER Muhammad Edwin < emuhamma at redhat dot com >

# Some version information
LABEL io.k8s.description="Platform for running plain Java applications (fat-jar and flat classpath)" \
      io.k8s.display-name="My Simple Java Applications" \
      io.openshift.tags="builder,java" \
      org.jboss.deployments-dir="/deployments" \
      com.redhat.deployments-dir="/deployments" \"JAVA_DEBUG:false" \"JAVA_DEBUG_PORT:5005"

# Install Java runtime
RUN microdnf install java-11-openjdk-headless --nodocs \
 && microdnf install shadow-utils && microdnf clean all \
 && mkdir /deployments

# Add user & group
RUN groupadd jboss && useradd jboss -g jboss

# Use /dev/urandom to speed up startups & Add jboss user to the root group
RUN echo securerandom.source=file:/dev/urandom >> /usr/lib/jvm/jre/lib/security/ \
 && usermod -g root -G jboss jboss

# set working directory at /deployments
WORKDIR /deployments

# copy corresponding jar file
COPY demo.jar demo.jar

# Necessary to permit running with a randomised UID
RUN mkdir -p /deployments/data \
 && chmod -R "g+rwX" /deployments \
 && chown -R jboss:jboss /deployments \
 && chmod 664 /etc/passwd

# gives uid
USER 185

# run it
CMD ["java","-jar","demo.jar"]

Create A Docker for Running Apache and PHP

Below is the script for creating a docker which contain Apache and PHP,

docker run --rm \
--detach \
--name=web_01 \
--net mynet \
--ip \
--publish 10209:80 \
--volume="$PWD"/apps:/app \
--volume="$PWD"/logs:/app/application/logs \
--workdir=/app \
-e PHP_DATE_TIMEZONE='Asia/Jakarta' \
-e LOG_STDOUT='/logs' \
-e LOG_STDERR='/logs' \