参考文档
测试机
10.193.10.201
10.193.10.202
10.193.10.203
安装Docker
1 2 3 4 5 6 7 8
| yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yum install -y docker-ce-19.03.13 docker-ce-cli-19.03.13 containerd.io docker --version systemctl enable docker systemctl start docker systemctl daemon-reload systemctl status docker
|
部署Swarm
1 2 3 4 5 6 7 8 9 10 11
| docker swarm init --advertise-addr 10.193.10.201
docker swarm join-token worker
docker swarm join --token SWMTKN-1-5ijp838v2gjyq0v85bl2reiptw7qk8cj7verfgjrfb97nun8yd-1215mjt92g7ahl7jnuyoxmpq1 10.193.10.201:2377
docker node ls
|
部署应用
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| docker service create --replicas 1 --name helloworld alpine ping baidu.com
docker service ls
docker service inspect --pretty helloworld
docker service ps helloworld
docker service rm helloworld
|
更新服务
1 2 3 4 5 6 7 8 9 10
| docker service create \ --replicas 3 \ --name redis \ --update-delay 10s \ redis:3.0.6
docker service update --image redis:3.0.7 redis docker service update redis
|
排除节点
1 2 3 4 5 6 7 8 9 10 11
| docker node update --availability drain playground03
docker node update --availability active playground03
docker node rm --force playground03
docker service update helloworld --force
|
端口映射
https://holynull.gitbooks.io/docker-swarm/content/kai-shi-shi-yong-swarm/swarmmo-shi-duan-kou-lu-you.html
1 2 3 4 5 6 7
| docker service create \ --name my-web \ --publish published=8080,target=80 \ --replicas 2 \ nginx
docker service inspect --format="{{json .Endpoint.Spec.Ports}}" my-web
|
测试:
http://10.193.10.201:8080
http://10.193.10.202:8080
http://10.193.10.203:8080
Stack
https://docs.docker.com/engine/reference/commandline/stack_deploy/
https://www.jianshu.com/p/25c529e3a3e6
1 2 3 4 5 6 7 8 9 10
| docker stack deploy -c docker-compose.yml wordpress
docker stack ls docker stack ps swarmpit docker stack services swarmpit
docker stack rm xxx
|
网络
https://zhuanlan.zhihu.com/p/129258067
1 2 3 4 5
| docker network ls
docker network create --driver overlay swarmnetwork
|
绑定多个节点
1 2 3 4 5 6 7 8 9
| docker node update --label-add h5=true playground01 docker node update --label-add h5=true playground02
vi compose.yml deploy: placement: constraints: [node.labels.h5 == true]
|
CPU/MEM限制
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| docker stats
docker service inspect --pretty admin_admin-service
docker node ls | cut -c 31-49 | grep -v HOSTNAME | xargs -I"SERVER" sh -c "echo SERVER; ssh SERVER docker stats --no-stream"
docker service update --reserve-cpu 2 --reserve-memory 512m h5-test_web-service
docker service update --limit-cpu 2 --limit-memory 512m h5-test_web-service
docker service update --limit-cpu 0 --limit-memory 0 --reserve-cpu 0 --reserve-memory 0 h5-test_web-service
|
服务伸缩
1 2 3 4 5
| docker service scale admin_admin-service=5
docker service ps admin_admin-service
|
查看service日志
1
| docker service logs -f --tail 0 hphz-es-service_bridge-service
|
常用操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| docker node ls
docker node inspect host101 --format '{{ .Status.Addr }}' docker service inspect --format="{{json .Endpoint.Spec.Ports}}" my-web
docker node inspect --pretty artiServer
docker service ls docker service inspect --pretty bridge-service_bridge-service docker service ps bridge-service_bridge-service
docker service scale helloworld=5
docker service update bridge-service_bridge-service --force
docker service scale hphz-es-service_bridge-service=1
docker stack rm h5-test-mazq
docker service logs -f --tail 10 hphz-es-service-temp_bridge-service-temp
docker stack rm hphz-es-service-temp export SERVICES_hphz_es_SERVICE_IMAGE=artifactory.sdecloud.com:8443/docker-local/hphz-es:RELEASE-1.197 docker stack deploy -c hphz-es-service-temp.yml hphz-es-service-temp --with-registry-auth
|