Docker swarm

Docker swarm 概述

Docker Swarm是Docker的本地群集,使用Docker Machine是用户首次使用Swarm的最佳方法

创建一个Docker集群

创建主机并生成令牌

列出系统上的机器

[root@lianxi ~]# docker-machine ls

创建一个名为 lianxi 的主机

[root@lianxi ~]# docker-machine create -d virtualbox lianxi

将l ianxi 主机的配置装入shell

[root@lianxi ~]# docker-machine env lianxi
[root@lianxi ~]# eval $(docker-machine env lianxi)

使用Docker Swarm 生成发现令牌(以下swarm create 命令在容器中运行命令)

[root@lianxi ~]# docker-machine ssh lianxi
docker@lianxi:~$ docker run swarm create
Unable to find image 'swarm:latest' locally
latest: Pulling from library/swarm
ad8c679cee1a: Pull complete 
97186f5f56a9: Pull complete 
821a304aaa0d: Pull complete 
Digest: sha256:1a05498cfafa8ec767b0d87d11d3b4aeab54e9c99449fead2b3df82d2744d345
Status: Downloaded newer image for swarm:latest
Token based discovery is now deprecated and might be removed in the future.
It will be replaced by a default discovery backed by Docker Swarm Mode.
Other mechanisms such as consul and etcd will continue to work as expected.
e2edcabb86d25787d0182101b94f292e  #令牌

将令牌保存到有个安全的地方,下一步会用到

启动 Swarm manager

创建一个 swarm manager 和两个节点

退出lianxi 容器

docker@lianxi:~$ exit

创建一个swarm  manage,命令格式如下

docker-machine create 
        -d virtualbox 
        --swarm 
        --swarm-master 
        --swarm-discovery token:/令牌 
        swarm-master

例如

[root@lianxi ~]#  docker-machine create 
                  -d virtualbox 
                  --swarm 
                  --swarm-master 
                  --swarm-discovery token://8c33b2a02009172d45c47188d65daf53 
                  swarm-master

创建一个群组节点

[root@lianxi ~]# docker-machine create 
                 -d virtualbox 
                 --swarm 
                 --swarm-discovery token://8c33b2a02009172d45c47188d65daf53 
                 swarm-agent-00

添加另一个代理调用swarm-agent-01

[root@lianxi ~]# docker-machine create 
                 -d virtualbox 
                 --swarm 
                 --swarm-discovery token://8c33b2a02009172d45c47188d65daf53 
                 swarm-agent-01
原文地址:https://www.cnblogs.com/wanglan/p/7473712.html