Detail: I'm trying to run wurstmeister/kafka and wurstmeister/zookeeper image using docker-compose.yml file which is attached at the bottom of this post.
To test the containers, I have followed the official site of kafka. It refers to some scripts like bin/kafka-server-start.sh
that isn't available in the image. I have also tried to go through the containers using docker exec -it zookeeper bash
and docker exec -it kafka bash
and found zkServer.sh and some other scripts in the /bin/
directory.
Problem: The problem is that I don't know how to use it, because the config/server.properties is available in the kafka container not zookeeper. So I'm not aware of the proper solution. Is it a good solution to download the scripts and put them in the host directory and copy them to the container?
docker-compose.yml
version:'2'
services:
zookeeper:
image: wurstmeister/zookeeper
container_name: zookeeper
ports:
- "2181:2181"
kafka:
build: .
container_name: kafka
links:
- zookeeper
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_OPTS: -javaagent:/usr/app/jmx_prometheus_javaagent.jar=7071:/usr/app/prom-jmx-agent-config.yml
volumes:
- /var/run/docker.sock:/var/run/docker.sock
Dockerfile
FROM wurstmeister/kafka
ADD prom-jmx-agent-config.yml /usr/app/prom-jmx-agent-config.yml
ADD jmx_prometheus_javaagent-0.10.jar /usr/app/jmx_prometheus_javaagent.jar
You don't have to use bin/kafka-server-start.sh
script. There is script called start-kafka.sh
in wurstmeister/kafka
image. Here is how I did it in one of my projects:
docker-compose.yml
zookeeper:
container_name: zookeper
image: wurstmeister/zookeeper:3.4.6
ports:
- "2181:2181"
kafka:
container_name: kafka
build:
context: .
dockerfile: kafka.Dockerfile
image: kafka-service
ports:
- "9092:9092"
kafka.Dockerfile
FROM wurstmeister/kafka:2.11-2.0.0
COPY wait-for-it.sh /wait-for-it.sh
RUN chmod +x /wait-for-it.sh
CMD ["/wait-for-it.sh", "zookeper:2181", "--", "start-kafka.sh"]
Here in dockerfile, I essentially say: "Wait for zookeeper, he has to be up first,then you can start, then after him, run start-kafka.sh
". You can download wait-for-it.sh script here: https://github.com/vishnubob/wait-for-it/blob/master/wait-for-it.sh
PS: You can see the essential information of any image using the following command:
docker inspect <image-name>
would you please write the equivalent docker-compose.yml file of the commands found in kafka official site?
Take a look at edited answer. You are missing CMD part of the dockerfile.
how about image: kafka-service?
kafka-image is built from kafka.Dockerfile. I included dockerfile because I had to enrich that official kafka image with wait-for-it.sh script since official kafka image doesn't include that script. You can go without that script ( CMD ["start-kafka.sh"] ), but I dont know what will happen if kafka start before zookeper.
I don't understand what is your question. If the question is how to write python producer, I don't know that, I am not familiar with python. If you are asking how to start kafka, I already answered, if you don't understand, clarify which part you don't understand so I can help a little bit more. If you want to run console producer, you can look at step 4. here kafka.apache.org/quickstart