目录
4. 启动第二个consul服务:consul2, 并加入consul1(使用join命令)
5. 启动第三个consul服务:consul3,并加入consul1
一、Consul
1. 拉取镜像
docker pull consul
2. 启动第一个consul服务:consul1
docker run --name consul1 -d -p 8500:8500 -p 8300:8300 -p 8301:8301 -p 8302:8302 -p 8600:8600 consul:1.2.2 agent -server -bootstrap-expect 2 -ui -bind=0.0.0.0 -client=0.0.0.0
3. 查看consul service1 的ip地址
4. 启动第二个consul服务:consul2, 并加入consul1(使用join命令)
docker run --name consul2 -d -p 8501:8500 consul agent -server -ui -bind=0.0.0.0 -client=0.0.0.0 -join 172.17.0.2
5. 启动第三个consul服务:consul3,并加入consul1
docker run --name consul3 -d -p 8502:8500 consul agent -server -ui -bind=0.0.0.0 -client=0.0.0.0 -join 172.17.0.2
二、API 讲解
1. 修改配置文件
[root@docker bin]# vi /etc/sysconfig/docker
curl -X GET http://localhost:2375/info
curl -X GET http://localhost:2375/version
curl -X GET http://localhost:2375/containers/json
curl -X POST -H "Content-Type: application/json" -d '{
"Image": "mariadb",
"Env": ["MYSQL_ROOT_PASSWORD=000000"],
"ExposedPorts": {
"3306/tcp": {}
},
"HostConfig": {
"PortBindings": {
"3306/tcp": [{"HostIp": "","HostPort": "3306"}]
}
},
"NetworkSettings": {
"Ports": {
"5000/tcp": [{"HostIp": "0.0.0.0","HostPort": "3306"}]
}
}
}' http://localhost:2375/containers/create
curl -X POST -H "Content-Type: application/json"
http://localhost:2375/containers/b20699b782bb/start
curl -X DELETE http://localhost:2375/containers/b20699b782bb
2. 获取 Docker 守护进程的信息
curl -X GET http://localhost:2375/info
3. 获取 Docker 守护进程的版本信息
curl -X GET http://localhost:2375/version
4. 获取当前所有容器的信息
curl -X GET http://localhost:2375/containers/json