During my¬† work on Karafka framework I have to start/stop/restart Apache Kafka and Zookeeper quite often. Here’s a short script that will pull the most recent version of Kafka and Zookeeper, will run them and print their IPs.

Note, that it will also stop Kafka and Zookeeper if they were running.

ZOOKEEPER_CHROOT='/kafka'

docker stop zookeeper
docker stop kafka
docker rm zookeeper
docker rm kafka

docker pull jplock/zookeeper
docker pull ches/kafka

docker run \
  -d \
  -e ZOOKEEPER_CHROOT=$ZOOKEEPER_CHROOT \
  --name zookeeper \
  jplock/zookeeper:3.4.6

docker run \
  -d \
  -e ZOOKEEPER_CHROOT=$ZOOKEEPER_CHROOT \
  --name kafka \
  --link zookeeper:zookeeper \
  ches/kafka

ZOOKEEPER_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' zookeeper)
KAFKA_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' kafka)

echo "Zookeeper chroot: $ZOOKEEPER_CHROOT"
echo "Zookeeper: $ZOOKEEPER_IP"
echo "Kafka: $KAFKA_IP"