Deploy a cluster on Docker

To deploy a Pulsar cluster on Docker using Docker commands, you need to complete the following steps.

Step 1: Pull a Pulsar image

To run Pulsar on Docker, you need to create a container for each Pulsar component: ZooKeeper, bookie, and the broker. You can pull the images of ZooKeeper and bookie separately on Docker Hub, and pull the Pulsar image for the broker. You can also pull only one Pulsar image and create three containers with this image. This tutorial takes the second option as an example.

You can pull a Pulsar image from Docker Hub with the following command. If you do not want to use some connectors, you can use apachepulsar/pulsar:latest there.

  1. docker pull apachepulsar/pulsar-all:latest

Step 2: Create a network

To deploy a Pulsar cluster on Docker, you need to create a network and connect the containers of ZooKeeper, bookie, and broker to this network. Use the following command to create the network pulsar:

  1. docker network create pulsar

Step 3: Create and start containers

Create a ZooKeeper container

Create a ZooKeeper container and start the ZooKeeper service.

  1. docker run -d -p 2181:2181 --net=pulsar \
  2. -e metadataStoreUrl=zk:zookeeper:2181 \
  3. -e cluster-name=cluster-a -e managedLedgerDefaultEnsembleSize=1 \
  4. -e managedLedgerDefaultWriteQuorum=1 \
  5. -e managedLedgerDefaultAckQuorum=1 \
  6. -v $(pwd)/data/zookeeper:/pulsar/data/zookeeper \
  7. --name zookeeper --hostname zookeeper \
  8. apachepulsar/pulsar-all:latest \
  9. bash -c "bin/apply-config-from-env.py conf/zookeeper.conf && bin/generate-zookeeper-config.sh conf/zookeeper.conf && exec bin/pulsar zookeeper"

Initialize the cluster metadata

After creating the ZooKeeper container successfully, you can use the following command to initialize the cluster metadata.

  1. docker run --net=pulsar \
  2. --name initialize-pulsar-cluster-metadata \
  3. apachepulsar/pulsar-all:latest bash -c "bin/pulsar initialize-cluster-metadata \
  4. --cluster cluster-a \
  5. --zookeeper zookeeper:2181 \
  6. --configuration-store zookeeper:2181 \
  7. --web-service-url http://broker:8080 \
  8. --broker-service-url pulsar://broker:6650"

Create a bookie container

Create a bookie container and start the bookie service.

  1. docker run -d -e clusterName=cluster-a \
  2. -e zkServers=zookeeper:2181 --net=pulsar \
  3. -e metadataServiceUri=metadata-store:zk:zookeeper:2181 \
  4. -v $(pwd)/data/bookkeeper:/pulsar/data/bookkeeper \
  5. --name bookie --hostname bookie \
  6. apachepulsar/pulsar-all:latest \
  7. bash -c "bin/apply-config-from-env.py conf/bookkeeper.conf && exec bin/pulsar bookie"

Create a broker container

Create a broker container and start the broker service.

  1. docker run -d -p 6650:6650 -p 8080:8080 --net=pulsar \
  2. -e metadataStoreUrl=zk:zookeeper:2181 \
  3. -e zookeeperServers=zookeeper:2181 \
  4. -e clusterName=cluster-a \
  5. -e managedLedgerDefaultEnsembleSize=1 \
  6. -e managedLedgerDefaultWriteQuorum=1 \
  7. -e managedLedgerDefaultAckQuorum=1 \
  8. --name broker --hostname broker \
  9. apachepulsar/pulsar-all:latest \
  10. bash -c "bin/apply-config-from-env.py conf/broker.conf && exec bin/pulsar broker"