docker search zookeeper
# 不要下载最新版本,有坑
docker pull zookeeper:3.4.14
docker images
docker run -d -p 2181:2181 --name zookeeper34 --restart always 3487af26dee9
注意yaml文件里不能有tab,只能有空格。
version: '3.1'
services:
zoo1:
image: zookeeper
restart: always
hostname: 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
hostname: 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
hostname: 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
补充:关于version与Docker版本的关系如下:
docker-compose up -d
$ docker exec -it zookeeper_zoo1_1 /bin/bash
$ cd /zookeeper-3.4.14/bin
$ ./zkServer.sh status
$ docker-compose stop
$ docker-compose rm
$root@zoo3:/zookeeper-3.4.14/bin# ./zkCli.sh -server localhost:2181
[zk: localhost:2181(CONNECTED) 3] create /demo "hello,zookeeper"
[zk: localhost:2181(CONNECTED) 4] get /demo
[zk: localhost:2181(CONNECTED) 5] delete /demo
[zk: localhost:2181(CONNECTED) 6] get /demo