编写 Docker-Compose 配置文件
创建 docker-compose.yml
配置文件,写入以下配置内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| version: "3.5"
services: zookeeper: image: bitnami/zookeeper:3.7.2 container_name: zookeeper restart: always ports: - 2181:2181 environment: - ALLOW_ANONYMOUS_LOGIN=yes - ZOOKEEPER_CLIENT_PORT=2181 - ZOOKEEPER_TICK_TIME=2000
|
创建并启动 ZooKeeper 容器
测试客户端连接 ZooKeeper 容器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| # docker exec -it zookeeper /bin/bash
# cd /opt/bitnami/zookeeper/bin
$ ./zkCli.sh -server 127.0.0.1:2181
[zk: 127.0.0.1:2181(CONNECTED) 1] create -e /test-node 123456
[zk: 127.0.0.1:2181(CONNECTED) 2] ls / [test-node, zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 3] get /test-node 123456
[zk: 127.0.0.1:2181(CONNECTED) 3] stat /test-node cZxid = 0x4 ctime = Fri Feb 22 02:27:43 UTC 2019 mZxid = 0x4 mtime = Fri Feb 22 02:27:43 UTC 2019 pZxid = 0x4 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x1000a766c5e0001 dataLength = 6 numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 4] quit
|