在 docker 群中部署多个动物园管理员

Deploying multiple zookeepers in docker swarm

我正在尝试使用 Docker Swarm 部署多个动物园管理员(每个都在自己的容器中)。

最终我想使用 3 个动物园管理员,但现在我只想让 2 个实例正常工作。

我现在的docker-compose.yml:

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

kafkaNetwork是我使用命令创建的覆盖网络

docker network create -d overlay --attachable kafkaNetwork

我找到了以下 docker 论坛 post https://forums.docker.com/t/cannot-get-zookeeper-to-work-running-in-docker-using-swarm-mode/27109/3 但无法成功让我的 zookeeper 实例正常工作。

已解决。

version: '3.2'

services:
  zoo1:
    image: zookeeper
    restart: always
    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 server.3=zoo3:2888:3888

  zoo2:
    image: zookeeper
    restart: always
    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 server.3=zoo3:2888:3888

  zoo3:
    image: zookeeper
    restart: always
    hostname: zoo3
    ports:
      - 2183:2181
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=0.0.0.0:2888:3888