docker-compose命令在kafka-zookeeper安装程序中给出错误

时间:2018-04-24 11:53:17

标签: docker apache-kafka docker-compose apache-zookeeper

我正在尝试将kafka与zookeeper同步,为此我在以下路径中保留了两个文件:

wait-for.sh

version: "2.1" services: zookeeper: image: confluentinc/cp-zookeeper:4.0.0 restart: always hostname: host container_name: zookeeper environment: ZOOKEEPER_SERVER_ID: 1 ZOOKEEPER_CLIENT_PORT: 32181 ZOOKEEPER_TICK_TIME: 2000 volumes: - $PWD/scripts/security:/etc/kafka/secrets ports: - "32181:32181" kafka: image: modkafka hostname: host container_name: kafka depends_on: - zookeeper command: sh -c '/subdir/wait-for.sh localhost:32181' volumes: - $PWD/scripts/security:/etc/kafka/secrets - ./subdir:/subdir ports: - "29092:29092" environment: KAFKA_ZOOKEEPER_CONNECT: "localhost:32181" KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:29092" KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 是从Eficode获取的脚本,用于检查主机和端口的可用性,并且它在本地运行正常。 docker-compose文件包含以下内容:

kafka        |   export KAFKA_LISTENERS
kafka        |   KAFKA_LISTENERS=$(cub listeners "$KAFKA_ADVERTISED_LISTENERS")
kafka        | fi
kafka        | + [[ -z '' ]]
kafka        | + export KAFKA_LISTENERS
kafka        | cub listeners "$KAFKA_ADVERTISED_LISTENERS"
kafka        | ++ cub listeners 'PLAINTEXT://localhost:29092"'
zookeeper    | sh: 1: ./wait-for: not found
zookeeper    | sh: 1: ./wait-for: not found
zookeeper    | sh: 1: ./wait-for: not found
kafka        | + KAFKA_LISTENERS='PLAINTEXT://0.0.0.0:29092"'
kafka        | 
kafka        | dub path /etc/kafka/ writable
kafka        | + dub path /etc/kafka/ writable
zookeeper exited with code 127

当我触发这个撰写文件时,kafka之前被触发并且我收到了以下错误:

FROM confluentinc/cp-kafka:4.0.0
RUN mkdir subdir

更新

我为kafka创建了新的dockerfile,提到了以下内容:

docker build -t modkafka .

并按以下方式构建:

root@sevenos:/home/sevenos/Downloads/dockerrun# docker exec -it kafka bash
root@sevenos:/# ls
bin   dev  home  lib64  mnt  proc  run   srv     sys  usr
boot  etc  lib   media  opt  root  sbin  subdir  tmp  var
root@sevenos:/# cd subdir

问题仍然存在。

对modkafka执行bash会产生以下输出:

version: "2.1"
services:
  zookeeper:
    image: confluentinc/cp-zookeeper:4.0.0
    restart: always
    hostname: host
    container_name: zookeeper
    environment:
      ZOOKEEPER_SERVER_ID: 1
      ZOOKEEPER_CLIENT_PORT: 32181
      ZOOKEEPER_TICK_TIME: 2000
    volumes:
      - $PWD/scripts/security:/etc/kafka/secrets

    ports:
      - "32181:32181"

  kafka:
    image: modkafka
    hostname: host
    container_name: kafka
    depends_on:
      - zookeeper
    command: sh -c '/subdir/wait-for.sh localhost:32181'
    volumes:
      - $PWD/scripts/security:/etc/kafka/secrets
      - ./subdir:/subdir
    ports:
      - "29092:29092"
    environment:
      KAFKA_ZOOKEEPER_CONNECT: "localhost:32181"
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:29092"
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

更新了docker-compose.yml文件:

{{1}}

1 个答案:

答案 0 :(得分:0)

您需要将脚本wait-for.sh包含在容器中。

为此,您可以在容器内安装包含脚本的目录。我建议将wait-for.sh移动到目录中,以确保容器不会从主机访问任何其他内容。假设您将脚本移动到subdir,那么您的撰写文件应该如下所示:

version: "2.1"
services:
  zookeeper:
    image: confluentinc/cp-zookeeper:4.0.0
    restart: always
    hostname: host
    container_name: zookeeper
    environment:
      ZOOKEEPER_SERVER_ID: 1
      ZOOKEEPER_CLIENT_PORT: 32181
      ZOOKEEPER_TICK_TIME: 2000
    volumes:
      - $PWD/scripts/security:/etc/kafka/secrets
    ports:
      - "32181:32181"
  kafka:
    image: confluentinc/cp-kafka:4.0.0
    hostname: host
    container_name: kafka
    depends_on:
      - zookeeper
    volumes:
      - $PWD/scripts/security:/etc/kafka/secrets
      - ./subdir:/subdir
    ports:
      - "29092:29092"
    command: sh -c '/subdir/wait-for.sh localhost:32181'
    environment:
      KAFKA_ZOOKEEPER_CONNECT: "localhost:32181"
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:29092"
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1