编写Dockerfile
FROM openjdk:17-jdk-slim
RUN apt update && apt upgrade -y && apt install -y curl
RUN curl https://downloads.apache.org/kafka/3.6.0/kafka_2.13-3.6.0.tgz -o kafka_2.13-3.6.0.tgz && tar xvf kafka_2.13-3.6.0.tgz && rm kafka_2.13-3.6.0.tgz
WORKDIR /kafka_2.13-3.6.0
RUN echo <<EOF > script.sh
#!/bin/bash
bin/zookeeper-server-start.sh config/zookeeper.properties
bin/kafka-server-start.sh config/server.properties
EOF
COPY --chmod=755 script.sh /kafka_2.13-3.6.0
EXPOSE 9092
CMD ./script.sh
执行命令制作和启动
docker build -t mykafka .
docker run -itd -p 9092:9092 --rm --name my_kafka mykafka