`
sillycat
  • 浏览: 2551820 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Docker Swarm 2020(1)Simply Install and Use Swarm

 
阅读更多
Docker Swarm 2020(1)Simply Install and Use Swarm

Check my Docker
> docker --version
Docker version 19.03.8, build afacb8b

Swarm Manager - rancher-home
Swarm Worker - rancher-worker1
Swarm Worker - rancher-worker2

Some useful ports:
2377 - cluster management
7946 - node to node
4789 - overlay network

On rancher-home
> docker swarm init --advertise-addr 192.168.56.110
Swarm initialized: current node (st1b4xuylrj6mm5oggsk6hp04) is now a manager.
To add a worker to this swarm, run the following command:
    docker swarm join --token SWMTKN-1-3ak17tlxe1ljqv8pk7gn1kwrjbz9hzgkn48wh8vu27o39ypjf6-b4mxpq45n2y0i6dpel3hwjlyw 192.168.56.110:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

If I forget about the token information just in case
> docker swarm join-token worker
To add a worker to this swarm, run the following command:
    docker swarm join --token SWMTKN-1-3ak17tlxe1ljqv8pk7gn1kwrjbz9hzgkn48wh8vu27o39ypjf6-b4mxpq45n2y0i6dpel3hwjlyw 192.168.56.110:2377

> docker info
Swarm: active
  NodeID: st1b4xuylrj6mm5oggsk6hp04
  Is Manager: true
  ClusterID: linol1nuatvwjbvquh1fg7x8h
  Managers: 1
  Nodes: 1
  Default Address Pool: 10.0.0.0/8 
  SubnetSize: 24
  Data Path Port: 4789

> docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
st1b4xuylrj6mm5oggsk6hp04 *   rancher-home        Ready               Active              Leader              19.03.8

Add the worker node to the swarm cluster
On rancher-worker1
> docker --version
Docker version 19.03.8, build afacb8b

Join the cluster
> docker swarm join --token SWMTKN-1-3ak17tlxe1ljqv8pk7gn1kwrjbz9hzgkn48wh8vu27o39ypjf6-b4mxpq45n2y0i6dpel3hwjlyw 192.168.56.110:2377

On rancher-worker2
> docker --version
Docker version 19.03.8, build afacb8b

> docker swarm join --token SWMTKN-1-3ak17tlxe1ljqv8pk7gn1kwrjbz9hzgkn48wh8vu27o39ypjf6-b4mxpq45n2y0i6dpel3hwjlyw 192.168.56.110:2377

On the manager machine, we can see all the nodes
> docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
st1b4xuylrj6mm5oggsk6hp04 *   rancher-home        Ready               Active              Leader              19.03.8
d85e6hmp2saf2xfyiq8nopvkp     rancher-worker1     Ready               Active                                  19.03.8
ccr3520glvgpyg7dn1zbkr8zg     rancher-worker2     Ready               Active                                  19.03.8

Remove the node from cluster
> docker swarm leave
Node left the swarm.

> docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
st1b4xuylrj6mm5oggsk6hp04 *   rancher-home        Ready               Active              Leader              19.03.8
d85e6hmp2saf2xfyiq8nopvkp     rancher-worker1     Ready               Active                                  19.03.8
ccr3520glvgpyg7dn1zbkr8zg     rancher-worker2     Down                Active                                  19.03.8

Remove it from the manager
> docker node rm --force ccr3520glvgpyg7dn1zbkr8zg
ccr3520glvgpyg7dn1zbkr8zg

> docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
st1b4xuylrj6mm5oggsk6hp04 *   rancher-home        Ready               Active              Leader              19.03.8
d85e6hmp2saf2xfyiq8nopvkp     rancher-worker1     Ready               Active                                  19.03.8

Manager and Deploy Service
Create a simple service
> docker service create --replicas 1 --name helloworld alpine ping docker.com
m45as37skje2gts6t6curew77
overall progress: 1 out of 1 tasks
1/1: running   [==================================================>]
verify: Service converged

List the service
>  docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
m45as37skje2        helloworld          replicated          1/1                 alpine:latest

Check the detail
> docker service inspect --pretty helloworld
ID: m45as37skje2gts6t6curew77
Name: helloworld
Service Mode: Replicated
Replicas: 1
Placement:
UpdateConfig:
Parallelism: 1
On failure: pause
Monitoring Period: 5s
Max failure ratio: 0
Update order:      stop-first

List the server information
> docker service ps helloworld
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE                ERROR               PORTS
vo5d6agsy1dw        helloworld.1        alpine:latest       rancher-home        Running             Running about a minute ago

Scale the service to 5
> docker service scale helloworld=5

List all the services
> docker service ps helloworld
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR                         PORTS
30nlrg5uu4c8        helloworld.1        alpine:latest       rancher-home        Running             Running 3 minutes ago                                 
vo5d6agsy1dw         \_ helloworld.1    alpine:latest       rancher-home        Shutdown            Failed 3 minutes ago     "task: non-zero exit (255)"  
fa9e3qlmcm47        helloworld.2        alpine:latest       rancher-worker2     Running             Running 30 seconds ago                                
8mr4dyaga779        helloworld.3        alpine:latest       rancher-worker1     Running             Running 29 seconds ago                                
7hbk7w99fo8z        helloworld.4        alpine:latest       rancher-worker1     Running             Running 29 seconds ago                                
0s7rbd9vwv3r        helloworld.5        alpine:latest       rancher-home        Running             Running 35 seconds ago 

Remove the service
> docker service rm helloworld

Run and Update the Tomcat Service
> docker service create --replicas 1 --name tomcat-service tomcat:8.5.8

Scale up to 2
> docker service scale tomcat-service=2

Rolling update to  tomcat:9.0.33
> docker service update --image tomcat:9.0.33 tomcat-service

Check status
> service ps tomcat-service
ID                  NAME                   IMAGE               NODE                DESIRED STATE       CURRENT STATE                 ERROR               PORTS
tei2ojnu7jxk        tomcat-service.1       tomcat:9.0.33       rancher-worker2     Running             Running 33 seconds ago                           
p6fg4k7l2jie         \_ tomcat-service.1   tomcat:8.5.8        rancher-worker2     Shutdown            Shutdown 53 seconds ago                          
q2it5kmfvois        tomcat-service.2       tomcat:9.0.33       rancher-home        Running             Running 55 seconds ago                           
e3dnf70mx0km         \_ tomcat-service.2   tomcat:8.5.8        rancher-home        Shutdown            Shutdown about a minute ago                      
r5kvdoruqdcf        tomcat-service.3       tomcat:9.0.33       rancher-worker1     Running             Running about a minute ago                       
33j1j47rk4pn         \_ tomcat-service.3   tomcat:8.5.8        rancher-worker1     Shutdown            Shutdown about a minute ago

Only see 3 history
> docker swarm update --task-history-limit 3


References:
https://yq.aliyun.com/articles/225511
https://outmanzzq.github.io/2019/06/14/portainer-for-docker-swarm/
https://note.qidong.name/2018/11/docker-swarm/
https://www.jianshu.com/p/df744c4e375e
https://github.com/jasonGeng88/blog/blob/master/201704/docker_swarm.md
https://stackoverflow.com/questions/41705134/how-can-i-remove-shutdown-docker-service-tasks-after-a-rolling-update

Maybe an useful tool
https://github.com/docker/machine


分享到:
评论

相关推荐

    Python-DockerSwarm模式集群操作API封装和SwarmUI的中间层应用

    在IT行业中,Python和Docker Swarm的结合是构建可扩展、高效且易于管理的微服务架构的关键技术之一。本文将深入探讨如何利用Python对Docker Swarm集群进行操作API的封装,以及如何创建一个Swarm UI的中间层应用,...

    Docker Swarm 管理资源.rar

    1. **Docker Swarm介绍** Docker Swarm是一种原生的集群管理器,它允许用户将多个Docker主机组成一个单一的虚拟系统,这被称为Swarm模式。在Swarm中,你可以创建服务,这些服务可以自动在可用的节点上扩展或收缩,...

    docker swarm 20.10.17 + portainer-ce 2.14.2 + nginx 1.23.1 离线包

    在IT行业中,Docker Swarm、Portainer CE和Nginx是三个非常重要的工具,它们各自在容器编排、管理以及Web服务器领域发挥着关键作用。本文将深入探讨这些组件的功能、用途及其最新版本20.10.17、2.14.2和1.23.1的特点...

    Docker Swarm架构的特性与基本实践.docx

    Docker Swarm 架构的特性与基本实践 Docker Swarm 架构是一种容器编排工具,提供了强大的集群管理和编排功能。 SwarmKit 是 Docker Engine 内置支持的一种默认实现,自 Docker 1.12 版本开始 unterstützt。通过 ...

    第四章:Docker容器升华--swarm集群1

    1. **初始化集群**:在一台主机上执行 `docker swarm init` 命令,获取加入集群所需的 token。 2. **加入集群**:其他主机使用 `docker swarm join` 命令,用管理节点的 token 和 IP 加入集群。 3. **检查集群状态**...

    DockerSwarm的一个可视化工具使用DockerRemoteAPINodeJS和D3实现

    Docker Swarm是一个强大的容器编排系统,它允许用户在多台主机上管理和部署容器化应用。在这个项目中,我们探讨的是一个使用Docker Remote API、Node.js和D3.js库来实现Docker Swarm集群可视化的工具。这个工具可以...

    docker swarm 集群搭建和试验

    docker swarm join --token SWMTKN-1-0597678294436-9911783060115-6114479547251323120 192.168.249.130:2377 ``` 查看集群状态,确认所有 Manager 节点的状态。正常情况下,应该只有一个 Leader 节点,其他为 ...

    docker SWARM 部署教程

    ### Docker Swarm 部署教程知识点详解 #### Docker Swarm 简介 Docker Swarm 是 Docker 官方提供的容器集群管理工具,它允许用户将多个 Docker 主机组织成一个集群,并通过一个统一的 API 来管理和调度容器。Swarm ...

    Go-将功能作为服务(在DockerSwarm之上)

    将功能作为服务(在Docker Swarm之上)

    使用Docker swarm初始化一个集群.pptx

    **Docker Swarm 知识点详解** Docker Swarm 是 Docker 的一种集群管理工具,它允许用户将多个 Docker 主机组织成一个单一的虚拟系统,从而实现容器化应用的集群化部署和管理。以下是对 Docker Swarm 初始化和管理的...

    docker swarm部署springcloud1

    1. **Docker Swarm**:Docker Swarm是Docker的集群管理工具,它将多个Docker宿主机转换为一个单一的虚拟系统,允许用户在一个分布式系统上进行服务部署和管理。在本场景中,Docker Swarm被用来部署Spring Cloud应用...

    docker_swarm_service_componse.yml

    docker swarm部署分布式微服务编排文件示例

    Linux运维-运维课程MP4频-05容器-69dockerswarm网络存储卷-nfs准备.mp4

    Linux运维-运维课程MP4频-05容器-69dockerswarm网络存储卷-nfs准备.mp4

    ansible-dockerswarm, 基于"Swarm Mode" 和Ansible的Docker 引擎.zip

    ansible-dockerswarm, 基于"Swarm Mode" 和Ansible的Docker 引擎 Ansible角色:Docker 群 在 Docker/centos和 debian/ubuntu服务器上使用新的Docker"发动机模式群"( https://docs.docker.com/engine/swarm/ ) 建立集

    mongo-swarm:在Docker Swarm上引导MongoDB分片集群

    使用单个命令,您可以将Mongos , Config和Data副本集部署到Docker Swarm上,形成一个高可用性的MongoDB集群,该集群能够在不中断服务的情况下承受多个节点的故障。 Docker堆栈由两个MongoDB副本集,两个Mongos实例...

    docker swarm 集群故障与异常详解

    本文介绍了docker swarm 集群故障与异常详解,分享给大家,具体如下: 在上次遭遇 docker swarm 集群故障后,我们将 docker 由 17.10.0-ce 升级为最新稳定版 docker 17.12.0-ce 。 前天晚上22:00之后集群中的2个...

Global site tag (gtag.js) - Google Analytics