-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
28 lines (22 loc) · 944 Bytes
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Image running Kafka and Zookeeper altogether,
# with an endless producer for testing
FROM ulitol97/kafka-zookeeper:dev
# 2181 is zookeeper, 9092 is kafka
EXPOSE 2181 9092
# Set topic name
ENV TOPIC_NAME test-topic
# Set wait between messages (millis)
ENV TIME_BETWEEN_MESSAGES 5000
# Install python/pip and python's kafka package
RUN apk add --update py3-pip && pip install kafka-python
# Copy the producer script into the machine /scripts
WORKDIR /scripts
COPY producer.py .
# 1. Start kafka and zookeeper via supervisord (as in parent image)
# 2. Create the kafka destination topic via kafka-scripts
# 3. Run the producer script in workdir, passing in the target topic
# (use ";" to keep going even if topic creation fails, as in the case of
# re-launching containers)
CMD supervisord && \
$KAFKA_HOME/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --topic $TOPIC_NAME; \
python3 producer.py $TOPIC_NAME