Docker create zookeeer container

Today, we built a cluster using a docker build ZK

First image download

docker pull zookeeper

When the following results appear to indicate downloaded image has been completed:

>>> docker pull zookeeper
Using default tag: latest
latest: Pulling from library/zookeeper
e110a4a17941: Pull complete
a696cba1f6e8: Pull complete
bc427bd93e95: Pull complete
c72391ae24f6: Pull complete
40ab409b6b34: Pull complete
d4bb8183b85d: Pull complete
0600755f1470: Pull complete
Digest: sha256:12458234bb9f01336df718b7470cabaf5c357052cbcb91f8e80be07635994464
Status: Downloaded newer image for zookeeper:latest

Start a command ZK

docker run --name my_zookeeper -d zookeeper:latest

Talk about today is to build a cluster using a docker-compose it to create a docker-compose.yaml configuration is as follows

version: '2'
services:
    zoo1:
        image: zookeeper
        restart: always
        container_name: zoo1
        ports:
            - "2181:2181"
        environment:
            ZOO_MY_ID: 1
            ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
    zoo2:
        image: zookeeper
        restart: always
        container_name: zoo2
        ports:
            - "2182:2181"
        environment:
            ZOO_MY_ID: 2
            ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
    zoo3:
        image: zookeeper
        restart: always
        container_name: zoo3
        ports:
            - "2183:2181"
        environment:
            ZOO_MY_ID: 3
            ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888

This image may be used instead of the ID image as the query image ID command

docker images

This configuration file tells Docker each running three zookeeper mirror, respectively, and the local 2181, 2182, 2183 port is bound to port 2181 on the corresponding container.
ZOO_MY_ID and ZOO_SERVERS are two environment variables to build ZK clusters to be set, ZOO_MY_ID which represents the id ZK services, it is an integer between 1-255, must be unique. ZOO_SERVERS is a list ZK host cluster in the cluster.

Then we run in the docker-compose.yml current directory:

COMPOSE_PROJECT_NAME=zk_test docker-compose up -d 

-d is the background to start

Use docker ps you can see the process

 

 Use the following command into the container

docker exec -it container the above mentioned id / bin / SH 
bin /zkServer.sh Status check the status of #

 

 This is from the node

 

 This is the primary node

 

Portal 1: https://blog.csdn.net/wu1226419614/article/details/78075898

Portal 2: https://www.jianshu.com/p/f9b257a3f948

Guess you like

Origin www.cnblogs.com/blackCatFish/p/12214981.html