Using Docker Desktop to build zookeeper cluster under win10

Keywords: Distribution

1. Installation

2. Configure alicloud

3. Get image

There are many online tutorials in these three steps, so I won't write them.
Because each version may bring some changes, I'll talk about the version I use

Docker Desktop 4.1.1
Windows 10 professional 21H1

4. Configure docker-compose.yml

If it is too troublesome to configure dockers one by one to do zk clustering, docker has a solution. A cluster can be built through a configuration file.
Create a configuration file named docker-compose.yml.

The docker command will automatically recognize the file name. If I can't afford to use this name, I haven't tried it. Those who are interested can figure it out for themselves.

For example, the number of clusters we want to create is three

version: '3.1'

    image: zookeeper
    restart: always
    hostname: zoo1
    container_name: zoo1
      - 2181:2181
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181

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

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

There's a big pit here. Be careful
Different versions of zk, zoom_ Servers are also different, and some need to be added; 2181, some do not need to be added.
The information found on the Internet does not need to be added before zookeeper 3.5, but after zookeeper 3.5.
Please refer to zookeeper's homepage in docker hub for specific writing:

If you report the following error, it's probably this; 2181 reason

ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Client port not found in static config file. Looking in dynamic config file.
grep: : No such file or directory
Client port not found. Terminating.

5. Start

Execute the command in the file directory of docker-compose.yml
Docker compose up - D - D does not print logs

Results after execution

PS C:\xxxxxxxx> docker-compose up -d
Creating network "desktop_default" with the default driver
Creating zoo1 ... done
Creating zoo3 ... done
Creating zoo2 ... done

Run docker ps to check whether the addition is successful. If you see the name in your configuration file, I have zoo1, zoo2 and zoo3, it indicates that the startup is successful.

6. Verify it

The ps command sees several services. Whether the service is started successfully or not, you still need to connect to the service to have a look

6.1 viewing zookeeper status

Connect to zoo1 and check the status of the service
docker exec -it zoo1 bash ./bin/ status

Return results

PS C:\xxxxxxxx> docker exec -it zoo1 bash ./bin/ status
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower

Mode: follower follower node
Mode: leader node

6.2 try connecting to a zk

Enter docker
docker exec -it zoo1 /bin/bash
Connection view
./bin/ -server
Execute the command casually to see if it succeeds
ls /

If you can return normally, you're done

Posted by hotcigar on Sat, 06 Nov 2021 08:55:02 -0700