Swarm 单节点快速上手

初始化

docker info 这个命令可以查看我们的docker engine有没有激活swarm模式, 默认是没有的,我们会看到

  1. Swarm: inactive

激活swarm,有两个方法:

  • 初始化一个swarm集群,自己成为manager
  • 加入一个已经存在的swarm集群

    1. > docker swarm init
    2. Swarm initialized: current node (vjtstrkxntsacyjtvl18hcbe4) is now a manager.
    3. To add a worker to this swarm, run the following command:
    4. docker swarm join --token SWMTKN-1-33ci17l1n34fh6v4r1qq8qmocjo347saeuer2xrxflrn25jgjx-7vphgu8a0gsa4anof6ffrgwqb 192.168.65.3:2377
    5. To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
    6. > docker node ls
    7. ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
    8. vjtstrkxntsacyjtvl18hcbe4 * docker-desktop Ready Active Leader 20.10.7

    docker swarm init 背后发生了什么

    主要是PKI和安全相关的自动化

  • 创建swarm集群的根证书

  • manager节点的证书
  • 其它节点加入集群需要的tokens

创建Raft数据库用于存储证书,配置,密码等数据
RAFT相关资料

  • http://thesecretlivesofdata.com/raft/
  • https://raft.github.io/
  • https://docs.docker.com/engine/swarm/raft/

    退出swarm使其为非激活状态

  • 使用docker swarm leave

    1. [root@localhost docker-exec]# docker swarm
    2. Usage: docker swarm COMMAND
    3. Manage Swarm
    4. Commands:
    5. ca Display and rotate the root CA
    6. init Initialize a swarm
    7. join Join a swarm as a node and/or manager
    8. join-token Manage join tokens
    9. leave Leave the swarm
    10. unlock Unlock swarm
    11. unlock-key Manage the unlock key
    12. update Update the swarm
    13. Run 'docker swarm COMMAND --help' for more information on a command.
    14. [root@localhost docker-exec]# docker swarm leave
    15. Error response from daemon: You are attempting to leave the swarm on a node that is participating as a manager. Removing the last manager erases all current state of the swarm. Use `--force` to ignore this message.
    16. [root@localhost docker-exec]# docker swarm leave --force
    17. Node left the swarm.