I have three nodes in docker swarm (all nodes are manager) I want to run zookeeper cluster on these three nodes
my docker-compose file
version: '3.8'
services:
zookeeper1:
image: 'bitnami/zookeeper:latest'
hostname: "zookeeper-1"
ports:
- '2181'
- '2888'
- '3888'
volumes:
- "zookeeper-1:/opt/bitnami/zookeeper/conf"
environment:
- ZOO_SERVER_ID=1
- ZOO_SERVERS=0.0.0.0:2888:3888,zookeeper-2:2888:3888,zookeeper-3:2888:3888
- ALLOW_ANONYMOUS_LOGIN=yes
networks:
- network_test
zookeeper2:
image: 'bitnami/zookeeper:latest'
hostname: "zookeeper-2"
ports:
- '2181'
- '2888'
- '3888'
volumes:
- "zookeeper-2:/opt/bitnami/zookeeper/conf"
environment:
- ZOO_SERVER_ID=2
- ZOO_SERVERS=zookeeper-1:2888:3888,0.0.0.0:2888:3888,zookeeper-3:2888:3888
- ALLOW_ANONYMOUS_LOGIN=yes
networks:
- network_test
zookeeper3:
image: 'bitnami/zookeeper:latest'
hostname: "zookeeper-3"
ports:
- '2181'
- '2888'
- '3888'
volumes:
- "zookeeper-3:/opt/bitnami/zookeeper/conf"
environment:
- ZOO_SERVER_ID=3
- ZOO_SERVERS=zookeeper-1:2888:3888,zookeeper-2:2888:3888,0.0.0.0:2888:3888
- ALLOW_ANONYMOUS_LOGIN=yes
networks:
- network_test
I use docker stack deploy to run, my expect is each zookeeper will run on different node, but sometimes one node will start two zookeeper conatiners
Does the docker stack deploy can have this feature??
thanks
To start a service on each available node in your Docker Swarm cluster you need to run it in global
mode.
But, in your case because of the specific volumes for each Zookeeper you can use placement constraints
to control the nodes a service can be assigned to. So you can add the following section to each Zookeeper service which will allow each instance to run on a different node:
services:
...
zookeeper-1:
...
deploy:
placement:
constraints:
- node.hostname==node1