Public | Automated Build

Last pushed: 12 days 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 customise 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

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 presendence 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 (17)
3 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
4 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 :|.


5 months ago

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

7 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

9 months ago

Thanks for the image(s).

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

9 months 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.

a year ago

Hi, can you explain please how I can add brokers with scale?

With this compose file:

version: '2'
    image: wurstmeister/zookeeper
      - "2181:2181"

    image: wurstmeister/kafka
      - zookeeper:zk
      - "9092:9092"
      - zookeeper
      - /var/run/docker.sock:/var/run/docker.sock

If i try docker-compose scale kafka=2 I get this error:

WARNING: The "kafka" service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash.
Creating and starting dockerlab_kafka_2 ... error
a year ago

Hi guy, an error found, any comments please? thanks
hs-zk | 2016-03-31 04:00:35,212 [myid:] - INFO [main:ZooKeeperServer@773] - maxSessionTimeout set to -1
hs-kafka | Cannot connect to the Docker daemon. Is the docker daemon running on this host?
hs-zk | 2016-03-31 04:00:35,227 [myid:] - INFO [main:NIOServerCnxnFactory@94] - binding to port
hs-kafka | [2016-03-31 04:00:36,053] FATAL (kafka.Kafka$)
hs-kafka | org.apache.kafka.common.config.ConfigException: Invalid value for configuration advertised.port: Not a number of type INT
hs-kafka | at org.apache.kafka.common.config.ConfigDef.parseType(
hs-kafka | at org.apache.kafka.common.config.ConfigDef.parse(
hs-kafka | at org.apache.kafka.common.config.AbstractConfig.<init>(
hs-kafka | at org.apache.kafka.common.config.AbstractConfig.<init>(
hs-kafka | at kafka.server.KafkaConfig.<init>(KafkaConfig.scala:702)
hs-kafka | at kafka.server.KafkaConfig$.fromProps(KafkaConfig.scala:691)
hs-kafka | at kafka.server.KafkaServerStartable$.fromProps(KafkaServerStartable.scala:28)
hs-kafka | at kafka.Kafka$.main(Kafka.scala:58)
hs-kafka | at kafka.Kafka.main(Kafka.scala)
hs-km | [warn] o.a.c.r.ExponentialBackoffRetry - maxRetries too large (100). Pinning to 29
hs-km | [info] k.m.a.KafkaManagerActor - Starting curator...
hs-km | [info] o.a.z.ZooKeeper - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
hs-km | [info] o.a.z.ZooKeeper - Client
hs-km | [info] o.a.z.ZooKeeper - Client environment:java.version=1.8.0_73
hs-km | [info] o.a.z.ZooKeeper - Client environment:java.vendor=Oracle Corporation