Public | Automated Build

Last pushed: a month ago
Short Description
Multi-Broker Apache Kafka Image
Full Description


Dockerfile for Apache Kafka

The image is available directly from Docker Hub


  • install docker-compose
  • modify the KAFKA_ADVERTISED_HOST_NAME in docker-compose.yml to match your docker host IP (Note: Do not use localhost or as the host ip if you want to run multiple brokers.)
  • if you want to customize any Kafka parameters, simply add them as environment variables in 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'


Start a cluster:

  • docker-compose up -d

Add more brokers:

  • docker-compose scale kafka=3

Destroy a cluster:

  • docker-compose stop


The 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. docker-compose-single-broker.yml:

  • docker-compose -f docker-compose-single-broker.yml up

Broker IDs

You can configure the broker id in different ways

  1. explicitly, using KAFKA_BROKER_ID
  2. via a command, using BROKER_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 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.

Automatically create topics

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:

      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.

Advertised hostname

You can configure the advertised hostname in different ways

  1. explicitly, using KAFKA_ADVERTISED_HOST_NAME
  2. via a command, using HOSTNAME_COMMAND, e.g. HOSTNAME_COMMAND: "route -n | awk '/UG[ \t]/{print $$2}'"

When using commands, make sure you review the "Variable Substitution" section in

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-



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

  • java.rmi.server.hostname - interface to bind listening port
  • - The port to service RMI requests

For example, to connect to a kafka running locally (assumes exposing port 1099)

  KAFKA_JMX_OPTS: " -Djava.rmi.server.hostname="
  JMX_PORT: 1099

Jconsole can now connect at jconsole


Docker Pull Command
Source Repository

Comments (19)
10 days ago

after start the kafka service i see the following logs. Perhaps someone faced with this issue and know the solution? Thanks
kafka_1 | [2017-06-13 14:18:52,307] WARN Unexpected error from /; closing connection (
kafka_1 | Invalid receive (size = 1195725856 larger than 104857600)
kafka_1 | at

a month ago

What is the version of this kafka image?

5 months ago

The zookeeper image you're using requires login. Make it available without log in so that Kafka doesn't fail.

docker-compose -f docker-compose-single-broker.yml up
Creating network "kafka_default" with the default driver
Pulling zookeeper (wurstmeister/zookeeper:latest)...
ERROR: Get unauthorized: incorrect username or password
6 months ago

Hi, is there an easy way to send and receive messages using java with this setup?
I have tried, but i get error that kafka tries 3x times to send messages and failed :|.


7 months ago

shit happend...
Ignoring APKINDEX.a2e6dac0.tar.gz: No such file or directory

9 months ago

hi man~ i am faced with some problem when use your project.The error code is :
kafka_1 | [2016-09-26 07:42:21,655] ERROR [KafkaApi-1002] Error when handling request {topics=[__consumer_offsets]} (kafka.server.KafkaApis)
kafka_1 | kafka.admin.AdminOperationException: replication factor: 3 larger than available brokers: 1
kafka_1 | at kafka.admin.AdminUtils$.assignReplicasToBrokers(AdminUtils.scala:117)
kafka_1 | at kafka.admin.AdminUtils$.createTopic(AdminUtils.scala:403)
kafka_1 | at kafka.server.KafkaApis.kafka$server$KafkaApis$$createTopic(KafkaApis.scala:629)
kafka_1 | at kafka.server.KafkaApis.kafka$server$KafkaApis$$createGroupMetadataTopic(KafkaApis.scala:651)
kafka_1 | at kafka.server.KafkaApis$$anonfun$29.apply(KafkaApis.scala:668)
kafka_1 | at kafka.server.KafkaApis$$anonfun$29.apply(KafkaApis.scala:666)
kafka_1 | at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
kafka_1 | at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
kafka_1 | at scala.collection.immutable.Set$Set1.foreach(Set.scala:94)
kafka_1 | at scala.collection.TraversableLike$
kafka_1 | at scala.collection.AbstractSet.scala$collection$SetLike$$super$map(Set.scala:47)
kafka_1 | at scala.collection.SetLike$
kafka_1 | at
kafka_1 | at kafka.server.KafkaApis.getTopicMetadata(KafkaApis.scala:666)
kafka_1 | at kafka.server.KafkaApis.handleTopicMetadataRequest(KafkaApis.scala:727)
kafka_1 | at kafka.server.KafkaApis.handle(KafkaApis.scala:79)
kafka_1 | at
kafka_1 | at

a year ago

Thanks for the image(s).

I had some issues, so I created an alternative approach,

a year ago

Hi. Thanks for your Docker image. I'd like to have an idea about the port of cluster. From Apache Kafka 0.9, Kafka doesn't rely on Zookeeper port as the center point anymore. Rather than that, users can communicate with broker IPs, ports. So, in case we create many Kafka brokers, we should be able to define the ports for them exactly. What do you think?

a year ago

how do i find docker-compose.yaml (on windows) ?

a year ago

Question: How to run this behind a proxy?

Unfortunately my server is behind a proxy and the "RUN apk add" command in Dockerfile could not execute since it could not fetch the APKINDEX.tar.gz file.