使用docker-compose可以很快速地搭建zookeeper集群。

zookeeper.yml

version: '3.1'

networks:
  docker_net:

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

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

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

执行docker-compose -f zookeeper.yml up,启动集群。

执行docker-compose -f zookeeper.yml ps,查看集群状态。

JNX5E6.jpg

刚开始还在想没有指定数据卷,删掉容器后,数据不就丢失了?

但使用docker inspect zoo1查看容器信息,可以看到容器里的\data,\logs,\datalog有挂载到宿主机的目录。

JNjcIf.jpg

Last modification:April 22nd, 2020 at 10:53 pm
如果觉得我的文章对你有用,请尽情赞赏 🐶