
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
https://img.shields.io/docker/pulls/wurstmeister/kafka.svg](https://hub.docker.com/r/wurstmeister/kafka/) https://img.shields.io/docker/stars/wurstmeister/kafka.svg](https://hub.docker.com/r/wurstmeister/kafka/) https://images.microbadger.com/badges/version/wurstmeister/kafka.svg](https://microbadger.com/images/wurstmeister/kafka "Get your own version badge on microbadger.com") https://images.microbadger.com/badges/image/wurstmeister/kafka.svg](https://microbadger.com/images/wurstmeister/kafka "Get your own image badge on microbadger.com") https://travis-ci.org/wurstmeister/kafka-docker.svg?branch=master](https://travis-ci.org/wurstmeister/kafka-docker)
Dockerfile for http://kafka.apache.org/
The image is available directly from https://hub.docker.com/r/wurstmeister/kafka/
KAFKA_ADVERTISED_PROTOCOL_NAME and KAFKA_PROTOCOL_NAME removed. Please update to canonical kafka settings.KAFKA_ZOOKEEPER_CONNECT is now a mandatory environment var.KAFKA_ADVERTISED_HOST_NAME in https://raw.githubusercontent.com/wurstmeister/kafka-docker/master/docker-compose.yml to match your docker host IP (Note: Do not use localhost or 127.0.0.1 as the host ip if you want to run multiple brokers.)docker-compose.yml, e.g. in order to increase the message.max.bytes parameter set the environment to KAFKA_MESSAGE_MAX_BYTES: 2000000. To turn off automatic topic creation set KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false'LOG4J_. These will be mapped to log4j.properties. For example: LOG4J_LOGGER_KAFKA_AUTHORIZER_LOGGER=DEBUG, authorizerAppenderNOTE: There are several 'gotchas' with configuring networking. If you are not sure about what the requirements are, please check out the https://github.com/wurstmeister/kafka-docker/wiki/Connectivity in the https://github.com/wurstmeister/kafka-docker/wiki
Start a cluster:
docker-compose up -d Add more brokers:
docker-compose scale kafka=3Destroy a cluster:
docker-compose stopThe default docker-compose.yml should be seen as a starting point. By default each broker will get a new port number and broker id on restart. Depending on your use case this might not be desirable. If you need to use specific ports and broker ids, modify the docker-compose configuration accordingly, e.g. https://github.com/wurstmeister/kafka-docker/blob/master/docker-compose-single-broker.yml:
docker-compose -f docker-compose-single-broker.yml upYou can configure the broker id in different ways
KAFKA_BROKER_IDBROKER_ID_COMMAND, e.g. BROKER_ID_COMMAND: "hostname | awk -F'-' '{print $2}'"If you don't specify a broker id in your docker-compose file, it will automatically be generated (see https://issues.apache.org/jira/browse/KAFKA-1070. This allows scaling up and down. In this case it is recommended to use the --no-recreate option of docker-compose to ensure that containers are not re-created and thus keep their names and ids.
If you want to have kafka-docker automatically create topics in Kafka during
creation, a KAFKA_CREATE_TOPICS environment variable can be
added in docker-compose.yml.
Here is an example snippet from docker-compose.yml:
environment: KAFKA_CREATE_TOPICS: "Topic1:1:3,Topic2:1:1:compact"
Topic 1 will have 1 partition and 3 replicas, Topic 2 will have 1 partition, 1 replica and a cleanup.policy set to compact.
If you wish to use multi-line YAML or some other delimiter between your topic definitions, override the default , separator by specifying the KAFKA_CREATE_TOPICS_SEPARATOR environment variable.
For example, KAFKA_CREATE_TOPICS_SEPARATOR: "$'\n'" would use a newline to split the topic definitions. Syntax has to follow docker-compose escaping rules, and https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html quoting.
You can configure the advertised hostname in different ways
KAFKA_ADVERTISED_HOST_NAMEHOSTNAME_COMMAND, e.g. HOSTNAME_COMMAND: "route -n | awk '/UG[ \t]/{print $2}'"When using commands, make sure you review the "Variable Substitution" section in https://docs.docker.com/compose/compose-file/
If KAFKA_ADVERTISED_HOST_NAME is specified, it takes precedence over HOSTNAME_COMMAND
For AWS deployment, you can use the Metadata service to get the container host's IP:
HOSTNAME_COMMAND=wget -t3 -T2 -qO- http://169.254.169.254/latest/meta-data/local-ipv4
Reference: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
If you require the value of HOSTNAME_COMMAND in any of your other KAFKA_XXX variables, use the _{HOSTNAME_COMMAND} string in your variable value, i.e.
KAFKA_ADVERTISED_LISTENERS=SSL://_{HOSTNAME_COMMAND}:9093,PLAINTEXT://9092
If the required advertised port is not static, it may be necessary to determine this programatically. This can be done with the PORT_COMMAND environment variable.
PORT_COMMAND: "docker port $(hostname) 9092/tcp | cut -d: -f2
This can be then interpolated in any other KAFKA_XXX config using the _{PORT_COMMAND} string, i.e.
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://1.2.3.4:_{PORT_COMMAND}
It may be useful to have the https://kafka.apache.org/documentation/ open, to understand the various broker listener configuration options.
Since 0.9.0, Kafka has supported https://issues.apache.org/jira/browse/KAFKA-1809 for brokers to help support different protocols and discriminate between internal and external traffic. Later versions of Kafka have deprecated advertised.host.name and advertised.port.
NOTE: advertised.host.name and advertised.port still work as expected, but should not be used if configuring the listeners.
The example environment below:
HOSTNAME_COMMAND: curl http://169.254.169.254/latest/meta-data/public-hostname KAFKA_ADVERTISED_LISTENERS: INSIDE://:9092,OUTSIDE://_{HOSTNAME_COMMAND}:9094 KAFKA_LISTENERS: INSIDE://:9092,OUTSIDE://:9094 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE
Will result in the following broker config:
advertised.listeners = OUTSIDE://ec2-xx-xx-xxx-xx.us-west-2.compute.amazonaws.com:9094,INSIDE://:9092 listeners = OUTSIDE://:9094,INSIDE://:9092 inter.broker.listener.name = INSIDE
You can configure the broker rack affinity in different ways
KAFKA_BROKER_RACKRACK_COMMAND, e.g. RACK_COMMAND: "curl http://169.254.169.254/latest/meta-data/placement/availability-zone"In the above example the AWS metadata service is used to put the instance's availability zone in the broker.rack property.
For monitoring purposes you may wish to configure JMX. Additional to the standard JMX parameters, problems could arise from the underlying RMI protocol used to connect
For example, to connect to a kafka running locally (assumes exposing port 1099)
KAFKA_JMX_OPTS: "-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.rmi.port=1099" JMX_PORT: 1099
Jconsole can now connect at jconsole 192.168.99.100:1099
The listener configuration above is necessary when deploying Kafka in a Docker Swarm using an overlay network. By separating OUTSIDE and INSIDE listeners, a host can communicate with clients outside the overlay network while still benefiting from it from within the swarm.
In addition to the multiple-listener configuration, additional best practices for operating Kafka in a Docker Swarm include:
ports: - target: 9094 published: 9094 protocol: tcp mode: host
Older compose files using the short-version of port mapping may encounter Kafka client issues if their connection to individual brokers cannot be guaranteed.
See the included sample compose file docker-compose-swarm.yml
http://wurstmeister.github.io/kafka-docker/
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务
以下是 wurstmeister/kafka 相关的常用 Docker 镜像,适用于 不同场景 等不同场景: