A docker image for kafka
255
Docker image containing a standard Kafka distribution.
Versions used in this docker image:
Image details:
To start the Kafka Docker image:
docker run -i -t bde2020/docker-kafka /bin/bash
To configure kafka we require to be provided with 2 JSON files; kafka-startup.json and kafka-init.json. Both files are expected to contain a JSON array of objects where each object represents a shell command to be executed. The kafka-startup.json should contain (at least) the command to start kafka within the docker.
There is a python script that will pick up these files when the container starts and convert the JSON objects to shell commands and execute them.
As an example of the kafka-startup.json file:
[
{
"sh":"/app/bin/kafka-server-start.sh",
"./config/server.properties":"",
"--override":[
"-Djava.net.preferIPv4Stack=true",
"zookeeper.connect=zookeeper:2181"
]
}
]
which will, by the python script, be converted to
sh /app/bin/kafka-server-start.sh ./config/server.properties --override -Djava.nete.preferIPv4Stack=true --override zookeeper.connect=zookeeper:2181
An example for the kafka-init.json would be:
[
{
"sh":"/app/bin/kafka-topics.sh",
"--zookeeper":"zookeeper:2181",
"--create":"",
"--topic":"sampleTopic",
"--partitions":"\"3\"",
"--replication-factor":"\"1\""
}
]
again ending up running the following shell command:
sh /app/bin/kafka-topics.sh --zookeeper zookeeper:2181 --create --topic sampleTopic --partitions: 3 --replication-factor 1
And also again there can be other commands chained to this one by adding objects to the JSON array.
To build the Kafka Docker image:
git clone https://github.com/big-data-europe/docker-kafka.git
docker build -t bde2020/docker-kafka .
To start a Kafka Server inside this Docker image
cd /usr/local/apache-kafka/current
./bin/kafka-start-server.sh ./config/server.properties
cd /usr/local/apache-kafka/current
./bin/kafka-start-server.sh ./config/server.properties \
--override zookeeper.connect=192.168.88.219:2181,192.168.88.229:2181
To start Kafka Docker image on Marathon:
{
"container": {
"type": "DOCKER",
"volumes": [
{
"containerPath": "/tmp/kafka-logs",
"hostPath": "/var/lib/bde/kafka-logs",
"mode": "RW"
}
],
"docker": {
"network": "BRIDGE",
"image": "bde2020/docker-kafka",
"privileged":true,
"portMappings": [
{ "containerPort": 9092, "hostPort": 9092}
]
}
},
"id":"apache-kafka",
"cpus": 0.2,
"mem": 512,
"cmd": "cd /usr/local/apache-kafka/current && ./bin/kafka-server-start.sh ./config/server.properties --override zookeeper.connect=192.168.88.219:2181,192.168.88.220:2181,192.168.88.221:2181/kafka --override delete.topic.enable=true --override advertised.host.name=$HOST --override advertised.port=$PORT0",
"instances":1,
"ports":[9092],
"requirePorts":true,
"constraints":[["hostname","UNIQUE",""]]
}
To create a Kafka topic:
docker ps
on one of the hosts. This will expose the containerId of the running bde2020/docker-kafka container, e.g. 8b797c0d80b3.
docker exec -t -i 8b797c0d80b3 /bin/bash
Inside the docker container cd into /usr/local/apache-kafka/current. Issue the following command to see available options for topic creation.
./bin/kafka-topics.sh --help
./bin/kafka-topics.sh --create --topic sampleTopic \
--zookeeper 192.168.88.219:2181/kafka \
--partitions 3 \
--replication-factor 1
./bin/kafka-topics.sh --list --zookeeper 192.168.88.219:2181/kafka
./bin/kafka-console-producer.sh --topic sampleTopic --broker-list bigdata-one.example.com:9092
After starting the producer simply type in some messages in the console and hit enter after every single message, we will consume these messages in the next step. Hit ctrl-c to stop the producer.
./bin/kafka-console-consumer.sh --topic sampleTopic \
--zookeeper 192.168.88.219:2181/kafka \
--bootstrap-server bigdata-one.example:9092 --from-beginning
To run the Kafka Image on the BDE Platform:
To run easily integrated with the BDE Platform this image provides the possibility to startup Apache Kafka and create a Kafka topic (in case it doesn't exist) using json config files.
These json files correspond to the many options that are available from Apache Kafka and are translated to Apache Kafka shell commands on the fly.
To run the Apache Kafka image using the BDE Platform, it is necessary to extend this image, adding to json files (see below) to the /config directory.
FROM bde2020/kafka
ADD kafka-startup.json /config/
ADD kafka-init.json /config/
[
{
"sh":"/app/bin/kafka-server-start.sh",
"./config/server.properties":"",
"--override":"-Djava.net.preferIPv4Stack=true",
"--override":"zookeeper.connect=192.168.88.219:2181,192.168.88.220:2181,192.168.88.221:2181/kafka"
}
]
* The kafka-init.json (example, the options are dependent on the use case)
```json
[
{
"sh":"/app/bin/kafka-topics.sh",
"--zookeeper":"192.168.88.219:2181,192.168.88.220:2181,192.168.88.221:2181/kafka",
"--create":"",
"--topic":"sampleTopic",
"--partitions":"3",
"--replication-factor":"1"
}
]
/app/bin/kafka-init
To run a Apache Kafka Cluster on docker-swarm
your-kafka-1:
image: "your/kafka-extension"
depends_on:
- your_zookeeper_1
- your_zookeeper_2
- your_zookeeper_3
ports:
- 9092:9092
command: "bash -c /app/bin/kafka-init"
hostname: "your-kafka-1"
your-kafka-2:
image: "your/kafka-extension"
depends_on:
- your_zookeeper_1
- your_zookeeper_2
- your_zookeeper_3
ports:
- 9092:9092
command: "bash -c /app/bin/kafka-init"
hostname: "your-kafka-2"
your-kafka-3:
image: "your/kafka-extension"
depends_on:
- your_zookeeper_1
- your_zookeeper_2
- your_zookeeper_3
ports:
- 9092:9092
command: "bash -c /app/bin/kafka-init"
hostname: "your-kafka-3"
Content type
Image
Digest
Size
108.7 MB
Last updated
over 8 years ago
docker pull flowofcontrol/docker-kafka