I'm trying to set up a single-broker per node kafka cluster using docker. The idea is multiple docker containers will contain a broker each, and I'll have another docker container as a zookeeper node. I'm building an image where I can pass the zookeeper address and the broker id as environment variables which will be used to start the broker. This will be useful to bring up multiple nodes with different broker id's by just passing them as env variables when I launch the container from the image.
This is my dockerfile:
FROM openjdk:8
RUN mkdir /kafka
WORKDIR /kafka
COPY kafka_2.12-2.3.0 kafka_2.12-2.3.0
COPY cmd.sh cmd.sh
RUN cat /etc/os-release
RUN chmod +x ./cmd.sh
CMD ["./cmd.sh"]
EXPOSE 9092
And this is my cmd.sh
#!/bin/sh
export KAFKA_DIR=/kafka/kafka_2.12-2.3.0
if [[ -z $KAFKA_BROKER_ID || -z $KAFKA_ZOOKEEPER_ADDRESS ]]; then
echo 'Zookeeper address and broker id need to be set by env variables KAFKA_ZOOKEEPER_ADDRESS and KAFKA_BROKER_ID'
exit 1
fi
echo "Broker ID: ${KAFKA_BROKER_ID}"
echo "Zookeeper addresss: ${KAFKA_ZOOKEEPER_ADDRESS}"
"${KAFKA_DIR}"/bin/kafka-server-start.sh "${KAFKA_DIR}"/config/server.properties --override broker.id="${KAFKA_BROKER_ID}" --override zookeeper.connect="${KAFKA_ZOOKEEPER_ADDRESS}"
I got this from the question How to check if multiple variables are defined or not in bash
I expect to see the error message but instead I'm getting this:
./cmd.sh: 5: ./cmd.sh: [[: not found ./cmd.sh: 5: ./cmd.sh: -z: not found Broker ID: Zookeeper addresss: [2019-07-03 08:56:04,172] INFO Registered kafka:type=kafka.Log4jController MBean (kafka.utils.Log4jControllerRegistration$) [2019-07-03 08:56:04,752] ERROR Exiting Kafka due to fatal exception (kafka.Kafka$) org.apache.kafka.common.config.ConfigException: Invalid value for configuration broker.id: Not a number of type INT