This repository contains the code to generate testing docker images with Kafka to be used in testing/development environment for easily check integrations.
These docker images are not intended to be used in production environments or scenarios where you need more control over the instance settings. This alpine-based images are intended to be as small as possible but they haven't been tuned in terms of performance.
To build the image we need to pass two arguments:
SCALA_VERSION
is used to specify the scala version to use.KAFKA_VERSION
is used to specify the kafka version to use.
If no arguments are passed, the latest scala and kafka versions will be used to build the latest image.
Using these arguments we can generate as many images as we need without having to rewrite the helper scripts.
docker build -t {name:tag} --build-arg SCALA_VERSION=2.11 --build-arg KAFKA_VERSION=1.1.0 .
See hooks/pre_build
for further information about how the tags are automatically
generated in the docker repository.
You can build your own image or use one of the images available at docker repository.
To run a basic instance that will accept connections as localhost
:
docker run -d -p 9092:9092 gguridi/kafka:latest
You can also specify any of the prebuilt images the automatic builds make available for you:
docker run -d -p 9092:9092 gguridi/kafka:2.11-2.0.0
Where the first part of the tag specifies the scala version, and the second one the kafka version. Check the tag list to see which versions are available.
The image is fully configurable through environment variables. We can override any default property of kafka/zookeeper using them.
The format accepted is the following:
- KAFKA__PROPERTY_NAME=value for server.properties (kafka) configuration.
- ZOOKEEPER__PROPERTY_NAME=value for zookeeper.properties (zookeeper) configuration.
The "_" of the property name will be replaced by dots, so as examples:
- This will set the property
advertised.host.name
of kafka tomy-docker-image
.
-e KAFKA__ADVERTISED_HOST_NAME=my-docker-image
Note: From kafka 3.x this property has changed to advertised.listeners
.
KAFKA__ADVERTISED_LISTENERS=PLAINTEXT://my-docker-image
- This will override the
listener
property to use several ports.
-e KAFKA__LISTENERS=PLAINTEXT://0.0.0.0:9092,SSL://0.0.0.0:9093
- This would override the
log.dir
property to use the folder/var/kafka/log
.
-e KAFKA__LOG_DIR=/var/kafka/log