Skip to content

Instantly share code, notes, and snippets.

@markrendle
Last active August 5, 2017 13:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save markrendle/658de32ada5190d14551 to your computer and use it in GitHub Desktop.
Save markrendle/658de32ada5190d14551 to your computer and use it in GitHub Desktop.
Vagrantfile to run Kafka in boot2docker

Kafka in Docker in Vagrant

I'm using this Vagrantfile to run Kafka on a Windows 8.1 laptop for development purposes.

It runs the ultra-lightweight boot2docker Linux, then uses Vagrant's Docker provisioning support to spin up ZooKeeper and Kafka.

The fun bits to work out were:

  • You need to forward the ports on both Vagrant (lines 13 & 14) and Docker (the -p flag), so you can access the instance from Windows using localhost:9092
  • You have to set the EXPOSED_HOST environment setting for Docker (line 22), otherwise the Kafka broker reports back with its internal (to Docker) IP address
VAGRANTFILE_API_VERSION = "2"
Vagrant.require_version ">= 1.6.3"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "boot2docker"
config.vm.box = "yungsang/boot2docker"
config.vm.synced_folder ".", "/vagrant"
# Uncomment below to use more than one instance at once
config.vm.network :forwarded_port, guest: 2181, host: 2181, auto_correct: true
config.vm.network :forwarded_port, guest: 9092, host: 9092, auto_correct: true
config.vm.provision :docker do |d|
d.run "jplock/zookeeper:3.4.6",
auto_assign_name: false,
args: "--name zookeeper -p 2181:2181"
d.run "ches/kafka",
auto_assign_name: false,
args: "--name kafka --link zookeeper:zookeeper -p 9092:9092 --env EXPOSED_HOST=127.0.0.1"
end
# Uncomment this to set up a "test" topic at startup
# config.vm.provision :shell do |s|
# s.inline = <<-EOT
# ZK_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' zookeeper)
# docker run --rm ches/kafka kafka-topics.sh --create --topic test --replication-factor 1 --partitions 1 --zookeeper localhost:2181
# EOT
# end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment