当前位置: 首页 > 知识库问答 >
问题:

Windows下使用Docker Compose运行Kafka的问题

臧俊杰
2023-03-14

我试图在Windows 10 Pro和Docker桌面上本地运行Kafka(而不是工具箱)。一切似乎都工作得很好,但我无法使用我的应用程序访问Kafka,也没有使用Kafka rest(http://localhost:8082/topics http://127.0.0.1:8082/topics http://192.168.1.103:8082/topics-最后一个是我在主机中的docker ip)

我的docker-compose文件是:

version: '2'

services:

  # https://hub.docker.com/r/confluentinc/cp-zookeeper/tags
  zookeeper:
    image: confluentinc/cp-zookeeper:5.3.1
    container_name: zookeeper
    hostname: zookeeper
    network_mode: host
    ports:
      - "2181:2181"
      - "32181:32181"
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181

  # https://hub.docker.com/r/confluentinc/cp-kafka/tags
  kafka:
    image: confluentinc/cp-kafka:5.3.1
    container_name: kafka
    hostname: kafka
    network_mode: host
    ports:
      - "9092:9092"
      - "29092:29092"
    restart: always
    environment:
      KAFKA_ADVERTISED_HOST_NAME: localhost
      KAFKA_CREATE_TOPICS: "test:1:1"
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
      KAFKA_ZOOKEEPER_CONNECT: localhost:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
      KAFKA_BROKER_ID: 2
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
    depends_on:
      - zookeeper

  schema-registry:
    image: confluentinc/cp-schema-registry:5.3.1
    hostname: schema-registry
    container_name: schema-registry
    network_mode: host
    depends_on:
      - zookeeper
      - kafka
    ports:
      - "8081:8081"
    environment:
      SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: localhost:2181
      SCHEMA_REGISTRY_HOST_NAME: localhost
      SCHEMA_REGISTRY_LISTENERS: http://localhost:8081

  kafka-rest:
    image: confluentinc/cp-kafka-rest:5.3.1
    hostname: kafka-rest
    container_name: kafka-rest
    network_mode: host
    depends_on:
      - zookeeper
      - kafka
    ports:
      - "8082:8082"
    environment:
      KAFKA_REST_HOST_NAME: localhost
      KAFKA_REST_ZOOKEEPER_CONNECT: localhost:2181
      KAFKA_REST_LISTENERS: http://localhost:8082
      KAFKA_REST_SCHEMA_REGISTRY_URL: http://localhost:8081

我的主机文件是:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost
192.168.1.103 host.docker.internal
192.168.1.103 gateway.docker.internal
# Added by Docker Desktop
192.168.2.236 host.docker.internal
192.168.2.236 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
127.0.0.1 kafka

在日志中,我有这样的消息:“Kafka-REST(2019-10-21 11:40:57,903)信息html" target="_blank">服务器启动,正在监听请求...(io.confluent.kafkarest.kafkarestmain)”

带有docker-compose的Kafka设置

和谷歌上的许多其他网站

共有1个答案

公西财
2023-03-14

考虑到Docker所涉及的网络,您需要正确配置Kafka监听器。这篇文章解释了如何:https://rmoff.net/2018/08/02/kafka-listeners-complinated/

您可以在以下位置找到包含主机访问的工作Docker组合:https://github.com/confluentinc/examples/blob/5.3.1-post/cp-all-in-one/docker-compose.yml

 类似资料:
  • 我正在OpenJDK 13中测试jpackage实用程序,以创建捆绑包和安装程序。只要我使用OpenJDK作为创建包的运行时,就可以在Windows和MacOS上运行。但OpenJDK13尚未发布,我喜欢使用OpenJDK12作为运行时。因此,我创建了一个OpenJDK12运行时,其中包含: 我在jpackage中使用这个运行时 创建的捆绑包没有错误消息。但当我尝试启动应用程序时,在Windows

  • 这些天我正在学习微服务架构,我需要运行Kafka来遵循一些教程。然而,zookeeper-server-start在cmd上运行Kafka的第一步对我来说不起作用。它说“命令的语法不正确” 我遵循了下面的过程 > 下载kafka和extarct(https://kafka.apache.org/downloads-kafka2.11-2.1.0.tgz(二进制下载)) bin\windows\zo

  • 我们开始Kafka,动物园管理员和Kafka连接在第一个盒子。我们也在第二个盒子里开始了Kafka连接。现在,根据confluent文档,我们必须使用REST API启动HDFS连接器(或任何其他连接器)。所以,在这两个框中启动kafka connect之后,我们尝试通过REST API启动connector。我们尝试了以下命令:- 当我们在这里按enter键时,我们得到以下响应: 位于etc/k

  • 我正在尝试构建一个包,以便在eclipse之外运行我的SWT应用程序。 在linux下,我成功地在bash下运行。但是当我尝试在windows下运行时,我收到以下错误: C: \纳芙林 我已经尝试指定参数-Djava.library.path,将SWT的DLL放在windows,windows/system,windows/system32… 我正在使用以下SWT JAR(随eclipse 32位

  • 我被以下错误困住了。我不知道这是什么类型的错误。我该怎么办?

  • 在Windows下使用时遇到问题。问题是在windows下该函数返回非UTF8编码的字符串(因为windows不支持UTF-8区域设置)。我在谷歌上搜索了很多关于这个主题的信息,找到了许多建议,只需使用,但这没有帮助。我在后面得到一个非常奇怪的字符串。还有另一种解决方案:使用例如: 这是可行的,但只有在开发一个精确的区域时才是好的。但我需要一个通用的解决方案。你可以建议: 但这不起作用,因为即使是