docker swarm 实验一 docker servi
更新:HHH   时间:2023-1-7


docker swarm 是一个docker宿主管理软件,还有k8s和mesos 作为同类容器管理软件,在docker 10.15之后合并进docker 不用单独在安装了

https://docs.docker.com/engine/swarm/services/

VirtualBox 开3个虚拟机


主机清单

swarm01 192.168.0.127

swarm02 192.168.0.128

swarm03 192.168.0.129


安装docker

$ curl -fsSL get.docker.com -o get-docker.sh

$ sudo sh get-docker.sh --mirror Aliyun

# $ sudo sh get-docker.sh --mirror AzureChinaCloud

sudo systemctl start docker

sudo systemctl enable docker

本机3网卡,在enp0s3 192.168.0.127 bridge网卡enp0s8上开始广播

docker swarm init --advertise-addr 192.168.0.127

work加入的密码

docker swarm join --token SWMTKN-1-0wlbnf7ezi6d39j7m0sv9912ikzf13f10jgk384ttiuj6ovy88-4sjlkdp9ul3fe353b0iq0q56c 192.168.0.127:2377

docker node ls

可以发现3台加入集群的机器

起一个hello的服务

docker search alpine

docker pull registry.docker-cn.com/library/alpine

docker service create --replicas 1 --name hello busybox

毛,registry 不在了?

nginx应该有吧

docker service create --name my_web nginx

docker service ls

创建一个task

docker service create --name helloworld alpine ping www.baidu.com

docker service ls

nginx服务加一个端口

docker service update --publish-add 80 my_web

docker service scale my_web=3

做错了还可以rollback

docker service update --replicas=5 my_web

docker service update --rollback my_web

192.168.0.127-129 3台服务器30000端口都可以访问到nginx的外网NAT端口3000

这30000的端口哪里来的,容我更新下

docker service update \

--publish-add published=80,target=80 \

my_web

node 80端口可以访问鸟

docker network ls

network 有两种,bridge是对外访问的,overlay是容器内部通讯的网络

docker network create -d overlay --attachable swarm_test

增加swarm通讯网卡

创建服务的时候制定网络

docker service create \
   --replicas 3 \
   --network swarm_test \
   --name my_web2 \
   nginx

比较下2个服务的区别

docker service inspect my_web

docker service inspect my_web2

走的网络是不一样的



其他docker services的命令

https://docs.docker.com/engine/reference/commandline/service_update/


docker service create

Create a new service

docker service inspect

Display detailed information on one or more services

docker service logs

Fetch the logs of a service or task

docker service ls

List services

docker service ps

List the tasks of one or more services

docker service rm

Remove one or more services

docker service rollback

Revert changes to a service’s configuration

docker service scale

Scale one or multiple replicated services

docker service update

Update a service

返回云计算教程...