本篇博客接上一篇
业务升级为APACHE
1,上传镜像
[root@foundation28 ~]# docker tag rhel7:v1 westos.org/rhel7:v1
[root@foundation28 ~]# docker push westos.org/rhel7:v1
2,更新升级
[root@server1 ~]# docker service update --image westos.org/rhel7:v1 --update-parallelism 3 --update-delay 10s nginx
nginx
--update-parallelism 同时更新的最大任务数
--update-delay 两次更新的间隔,单位默认为秒
[root@server1 ~]# docker service ls
ID NAME MODE REPLICAS IMAGE
2i51duq2sbmg viz replicated 1/1 westos.org/visualizer:latest
o4arvg4a3o9i nginx replicated 0/3 westos.org/rhel7:v1
[root@server1 ~]# docker service ls
ID NAME MODE REPLICAS IMAGE
2i51duq2sbmg viz replicated 1/1 westos.org/visualizer:latest
o4arvg4a3o9i nginx replicated 3/3 westos.org/rhel7:v1
更新完成
3,game2048更新
[root@foundation28 ~]# docker tag game2048 westos.org/game2048
[root@foundation28 ~]# docker push westos.org/game2048
[root@server1 ~]# docker service update --image westos.org/game2048 --update-parallelism 1 --update-delay 10s nginx # 这里的nginx是我们之前创建的服务名
nginx
4,回滚
[root@server1 ~]# docker service update --update-parallelism 1 --update-delay 5s --rollback nginx
nginx
[root@server1 ~]# docker service update --update-parallelism 1 --update-delay 5s --rollback nginx
nginx
如果在此执行这个命令那么又会滚到apache服务,在两个服务只见滚动,而不是一直往回滚
这里回滚回game2048的页面
并且如果我们停掉server2或server3的docker,不会影响访问172.25.28.1,还是可以正常玩游戏!因为有调度器帮助负载均衡
5,删除服务
[root@server1 ~]# docker service ls
ID NAME MODE REPLICAS IMAGE
2i51duq2sbmg viz replicated 1/1 westos.org/visualizer:latest
o4arvg4a3o9i nginx replicated 3/3 westos.org/rhel7:v1
[root@server1 ~]# docker service rm nginx
nginx
[root@server1 ~]# docker service rm viz
viz
[root@server1 ~]# docker service ls
ID NAME MODE REPLICAS IMAGE
6,解散集群
[root@server2 ~]# docker swarm leave
Node left the swarm.
[root@server3 ~]# docker swarm leave
Node left the swarm.
[root@server1 ~]# docker swarm leave --force
Node left the swarm.
DOCKER-MACHINE
Docker Machine 是 Docker 官方提供的一个工具,它可以帮助我们在远程的机器上安装 Docker,或者在虚拟机 host 上直接安装虚拟机并在虚拟机中安装 Docker。我们还可以通过 docker-machine 命令来管理这些虚拟机和 Docker。当我们部署成百上千个容器时,docker-machine比swarm或许更加方便
1,获取docker-machine二进制可执行文件
[root@foundation28 ~]# cd /usr/local/bin/
[root@foundation28 bin]# ls
docker-compose ntfs-3g.probe rht-vmctl
docker-compose-Linux-x86_64-1.22.0 ntfs-3g.secaudit rht-vmicons
firefox ntfs-3g.usermap rht-vmsetkeyboard
[root@foundation28 bin]# lftp 172.25.254.251
lftp 172.25.254.251:~> cd pub/docs/docker/
lftp 172.25.254.251:/pub/docs/docker> get docker-machine-Linux-x86_64-1.15.0
28160480 bytes transferred
lftp 172.25.254.251:/pub/docs/docker> exit
[root@foundation28 bin]# chmod +x docker-machine-Linux-x86_64-1.15.0
[root@foundation28 bin]# ln -s docker-machine-Linux-x86_64-1.15.0 docker-machine
[root@foundation28 bin]# docker-machine -v
docker-machine version 0.15.0, build b48dc28d
2,docker-machine是基于ssh免密部署
[root@foundation28 ~]# ssh-keygen
[root@foundation28 ~]# ssh-copy-id [email protected]
[root@foundation28 ~]# ssh-copy-id [email protected]
[root@foundation28 ~]# ssh-copy-id [email protected]
此时主机可以免密登录server1,server2,server3
3,加入控制
[root@foundation28 ~]# docker-machine create --driver generic --generic-ip-address=172.25.28.1 server1 # server1只是一个名字,用以区分节点
[root@foundation28 ~]# docker-machine create --driver generic --generic-ip-address=172.25.28.2 server2
[root@foundation28 ~]# docker-machine create --driver generic --generic-ip-address=172.25.28.3 server3
Running pre-create checks...
Creating machine...
(server3) No SSH key specified. Assuming an existing key at the default location.
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with redhat...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env server3
[root@foundation28 ~]# docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
server1 - generic Running tcp://172.25.28.1:2376 v17.03.1-ce
server2 - generic Running tcp://172.25.28.2:2376 v17.03.1-ce
server3 - generic Running tcp://172.25.28.3:2376 v17.03.1-ce
4,管理节点
[root@foundation28 ~]# docker-machine ssh server3 docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
6,删除节点
[root@foundation28 ~]# docker-machine rm server3
About to remove server3
WARNING: This action will delete both local reference and remote instance.
Are you sure? (y/n): y
Successfully removed server3