温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - Kafka and Zookeeper Scripts Not Found Using Docker

其他 - 使用Docker找不到Kafka和Zookeeper脚本

发布于 2020-03-27 10:30:50

详细信息:我正在尝试使用位于本文底部的docker-compose.yml文件运行wurstmeister / kafkawurstmeister / zookeeper图像。

为了测试容器,我遵循了kafka官方网站它指的bin/kafka-server-start.sh是图像中没有的类似脚本我还尝试使用docker exec -it zookeeper bash浏览了容器docker exec -it kafka bash并在/bin/目录中找到了zkServer.sh和其他一些脚本

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

查看更多

查看更多

提问者
Mostafa Ghadimi
被浏览
119
1,241 2019-07-03 21:57

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"]

在dockerfile中,我基本上是这样说的:“等一下动物园管理员,他必须先站起来,然后您可以启动,然后在他之后运行start-kafka.sh”。您可以在此处下载wait-for-it.sh脚本:https : //github.com/vishnubob/wait-for-it/blob/master/wait-for-it.sh

PS:您可以使用以下命令查看任何图像的基本信息:

docker inspect <image-name>

发布
问题

分享
好友

手机
浏览

扫码手机浏览