1. 安装:
使用Centos 版本3.10.0-862.6.3.el7.x86_64
#先清除原有版本
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate
#安装依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
#安装docker
yum install docker-ce docker-ce-cli containerd.io
#启动
systemctl start docker
2. docker基本信息
docker version
docker info
3. docker image和container操作
#查找镜像
docker search xxxxxx
#拉取镜像
docker pull xxxxx
#查看本地image
docker images 或 docker images ls
#查看container
docker container ls --all 或 docker ps -a
#启动 宿主机端口:container端口,-d是常驻后端
docker run -itd -p 4000:80 xxxxxx
#进入container内,如果内部无法vi,执行apt-get update、apt-get install vim
docker exec -it -u 0 xxxxxx bash
#可以使用rm来移除image和container,停止container用
4. docker compose 安装
yum install docker-compose
5. 使用docker compose安装zookeeper
#创建docker-compose.yml文件
version: '1'
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
端口2181、2182、2183将会暴露出来
#启动
docker-compose -f docker-compose.yml up
#查看
docker-compose ps
使用 Docker 命令行客户端连接 ZK 集群
docker run -it --rm --link zoo1:zk1 --link zoo2:zk2 --link zoo3:zk3
--net zktest_default zookeeper zkCli.sh -server zk1:2181,zk2:2181,zk3:2181
测试
echo stat | nc 127.0.0.1 2181