安装 YUM 源

[root@eca ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@eca ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@eca ~]# yum makecache fast

安装 Docker-CE

[root@eca ~]# yum list docker-ce
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
可安装的软件包
docker-ce.x86_64         3:18.09.0-3.el7          docker-ce-stable


[root@eca ~]# yum install -y docker-ce

开机自动启动

[root@eca ~]# systemctl start docker.service 
[root@eca ~]# systemctl enable docker.service 

初始化 Swarm 集群

## 初始化时指定网卡

[root@eca ~]# docker swarm init --advertise-addr 10.35.2.231
Swarm initialized: current node (446nt8ehugspxrpuwvhe7z5hc) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-2m86dmnuurd2p6i7ppou6k80hfwrp08xednqtr9qmb2nqnlznw-e52vn338pxwbpv4ku9vgm2fqy 10.35.2.231:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
添加管理节点
##
# To Add a Manager to This Swarm

[root@eca ~]# docker swarm join-token manager
To add a manager to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-2m86dmnuurd2p6i7ppou6k80hfwrp08xednqtr9qmb2nqnlznw-6hrbevz1t6a2b2gmb800szi4k 10.35.2.231:2377
[root@ecb ~]# docker swarm join --token SWMTKN-1-2m86dmnuurd2p6i7ppou6k80hfwrp08xednqtr9qmb2nqnlznw-6hrbevz1t6a2b2gmb800szi4k 10.35.2.231:2377
This node joined a swarm as a manager.


[root@ecc ~]# docker swarm join --token SWMTKN-1-2m86dmnuurd2p6i7ppou6k80hfwrp08xednqtr9qmb2nqnlznw-6hrbevz1t6a2b2gmb800szi4k 10.35.2.231:2377
This node joined a swarm as a manager.
[root@eca ~]# docker node ls                                         
ID                            HOSTNAME   STATUS   AVAILABILITY   MANAGER STATUS  ENGINE VERSION
446nt8ehugspxrpuwvhe7z5hc *   eca        Ready    Active         Leader          18.09.0
jda5jt62lsi3143r8rodw9zmm     ecb        Ready    Active         Reachable       18.09.0
wowt1wuxp7hzset1hk7xldg5p     ecc        Ready    Active         Reachable       18.09.0
添加工作节点
##
# To Add a Worker to This Swarm

[root@ecd ~]# docker swarm join --token SWMTKN-1-2m86dmnuurd2p6i7ppou6k80hfwrp08xednqtr9qmb2nqnlznw-e52vn338pxwbpv4ku9vgm2fqy 10.35.2.231:2377
This node joined a swarm as a worker.

[root@eca ~]# docker node ls
ID                            HOSTNAME   STATUS   AVAILABILITY   MANAGER STATUS  ENGINE VERSION
446nt8ehugspxrpuwvhe7z5hc *   eca        Ready    Active         Leader          18.09.0
jda5jt62lsi3143r8rodw9zmm     ecb        Ready    Active         Reachable       18.09.0
wowt1wuxp7hzset1hk7xldg5p     ecc        Ready    Active         Reachable       18.09.0
nso2wvibjbguleiuoflr1jpb9     ecd        Ready    Active                         18.09.0

You can use the docker command on any swarm manager or any replica.

Tips


[为隐藏内容,请登录(login)以显示!]