使用Docker Swarm Mode创建集群

能使用Docker Machine的前提是宿主机需要是物理机,云主机目前不支持Docker Machine的创建。

Virtualbox 安装

步骤可参考

cd /etc/yum.repos.d
wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
yum install VirtualBox-5.2

Docker Machine 安装

命令行安装docker-machine

base=https://github.com/docker/machine/releases/download/v0.15.0 &&
  curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine &&
  sudo ixunstall /tmp/docker-machine /usr/local/bin/docker-machine

创建docker-machine

docker-machine create --engine-registry-mirror=https://xxx.mirror.aliyuncs.com -d virtualbox manager
docker-machine create --engine-registry-mirror=https://xxx.mirror.aliyuncs.com -d virtualbox worker1
docker-machine create --engine-registry-mirror=https://xxx.mirror.aliyuncs.com -d virtualbox worker2

创建3台机器,manager为leader

使用Swarm Mode创建集群

初始化swarm集群manager

docker-machine ssh manager
docker swarm init
Swarm initialized: current node (bvz81updecsj6wjz393c09vti) is now a manager.

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

    docker swarm join --token SWMTKN-1-0bfpg588koug4bricwcs7y4edh70984pnpfx3tj1tmpb83atmn-442mbo6pueqsjcedq8aey04v0 192.168.99.100:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

机器加入到swarm集群

docker-machine ssh work1
docker swarm join --token SWMTKN-1-0bfpg588koug4bricwcs7y4edh70984pnpfx3tj1tmpb83atmn-442mbo6pueqsjcedq8aey04v0 192.168.99.100:2377

Swarm Mode集群部署

创建service服务

详细命令可参考,部署etcd 可参考

docker-machine ssh manager

docker network create --driver overlay db
docker service create --network db -e SERVICE_NAME=etcd -e MIN_SEEDS_COUNT=3 --replicas 3 --name etcd appcelerator/etcd

查看service服务

docker@manager:~$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
i0o3eu86v8qhf9pjfgpseytxq *   manager             Ready               Active              Leader              18.06.0-ce
tafuebh4yfm7c6a753xuq7hu1     worker1             Down                Active                                  18.06.0-ce
no9dktvpeslqipt6suc6d7va0     worker2             Down                Active                                  18.06.0-ce

其他service命令

其他详细的命令可参考

docker service inspect
docker service ls
docker service rm
docker service scale
docker service ps
docker service update
文章目录
  1. Virtualbox 安装
  2. Docker Machine 安装
    1. 命令行安装docker-machine
    2. 创建docker-machine
  3. 使用Swarm Mode创建集群
    1. 初始化swarm集群manager
    2. 机器加入到swarm集群
  4. Swarm Mode集群部署
    1. 创建service服务
    2. 查看service服务
    3. 其他service命令