title: Deploying multiple zookeepers in docker swarm
body: <p>I'm attempting to deploy multiple zookeepers (each in their own container) using Docker Swarm. </p>
  
  <p>Eventually I want to use 3 zookeepers, but for now I'm just trying to get 2 instances to work.</p>
  
  <p>My current docker-compose.yml:</p>
  
  <pre><code>version: '3'
  
  services:
    zoo1:
      image: zookeeper
      restart: unless-stopped
      hostname: zoo1
      ports:
        - 2181:2181
      environment:
          ZOO_MY_ID: 1
          ZOO_SERVERS: server.1=0.0.0.0:2888:3888;server.2=zoo2:2888:3888
      volumes:
        - ./full-stack/zoo1/data:/data
        - ./full-stack/zoo1/datalog:/datalog
      networks:
        - kafka_network
  
    zoo2:
      image: zookeeper
      restart: unless-stopped
      hostname: zoo2
      ports:
        - 2182:2181
      environment:
          ZOO_MY_ID: 2
          ZOO_SERVERS: server.1=zoo1:2888:3888;server.2=0.0.0.0:2888:3888
      volumes:
        - ./full-stack/zoo2/data:/data
        - ./full-stack/zoo2/datalog:/datalog
      networks:
        - kafka_network
  
    visualizer:
      image: dockersamples/visualizer:stable
      volumes:
        - "/var/run/docker.sock:/var/run/docker.sock"
      ports:
        - "8080:8080"
      deploy:
        placement:
          constraints: [node.role == manager]
  
  networks:
    kafka_network:
      external:
        name: kafkaNetwork
  </code></pre>
  
  <p>kafkaNetwork is an overlay network I created using the command</p>
  
  <pre><code>docker network create -d overlay --attachable kafkaNetwork
  </code></pre>
  
  <p>I found the following docker forum post <a href="https://forums.docker.com/t/cannot-get-zookeeper-to-work-running-in-docker-using-swarm-mode/27109/3" rel="nofollow noreferrer">https://forums.docker.com/t/cannot-get-zookeeper-to-work-running-in-docker-using-swarm-mode/27109/3</a> but wasn't able to successfully get my instances of zookeeper to work.</p>