docker-swarm简介
docker-swarm 是docker的一个本地集群工具,docker-swarm要求docker版本大于等于1.12,官方推荐使用docker-mechine创建docker-swarm群集,也可以手动创建
docker-swarm的安装
- docker官方推荐的安装方法,直接pull swarm镜像
优点1:能够运行最新的swarm
优点2:与主机隔离不用配置环境变量
1 | ➜ ~ docker run swarm --help |
从源码编译成二进制文件
在此不做赘述 具体方法可以参考githubmac os docker安装包集成了docker swarm,所以这也是一种最简便的安装方式
了解swarm集群 从创建一个简单的swram群集开始
创建一个keystory主机用于分发全球唯一的秘钥,并切换至keystory docker主机
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21➜ ~ docker-machine create -d virtualbox --engine-install-url=https://get.daocloud.io/docker/ keystory
Running pre-create checks...
Creating machine...
(keystory) Copying /Users/zlx/.docker/machine/cache/boot2docker.iso to /Users/zlx/.docker/machine/machines/keystory/boot2docker.iso...
(keystory) Creating VirtualBox VM...
(keystory) Creating SSH key...
(keystory) Starting the VM...
(keystory) Check network to re-create if needed...
(keystory) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env keystory
➜ ~ eval $(docker-machine env keystory)创建swarm秘钥
1
2
3
4
5
6
7
8
9➜ ~ docker create swarm
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
4bed323ad0b4f17ac960c427bd38e6111e5df1e1851f6f597bcd738901631034
记下秘钥串:
(4bed323ad0b4f17ac960c427bd38e6111e5df1e1851f6f597bcd738901631034)
创建swarm-msater
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25➜ ~ docker-machine create -d virtualbox \
> --swarm-master \
> --swarm \
> --swarm-discovery token://4bed323ad0b4f17ac960c427bd38e6111e5df1e1851f6f597bcd738901631034 \
> swarm-master
Running pre-create checks...
Creating machine...
(swarm-master) Copying /Users/zlx/.docker/machine/cache/boot2docker.iso to /Users/zlx/.docker/machine/machines/swarm-master/boot2docker.iso...
(swarm-master) Creating VirtualBox VM...
(swarm-master) Creating SSH key...
(swarm-master) Starting the VM...
(swarm-master) Check network to re-create if needed...
(swarm-master) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Configuring swarm...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env swarm-master创建2个node
1
2
3
4
5
6
7
8
9➜ ~ docker-machine create -d virtualbox \
--swarm \
--swarm-discovery token://4bed323ad0b4f17ac960c427bd38e6111e5df1e1851f6f597bcd738901631034 \
swarm-node01
➜ ~ docker-machine create -d virtualbox \
--swarm \
--swarm-discovery token://4bed323ad0b4f17ac960c427bd38e6111e5df1e1851f6f597bcd738901631034 \
swarm-node02查看docker host列表
1
2
3
4
5
6➜ zhichi docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
keystory - virtualbox Running tcp://192.168.99.100:2376 v17.06.2-ce
swarm-master - virtualbox Running tcp://192.168.99.101:2376 swarm-master (master) v17.06.2-ce
swarm-node01 - virtualbox Running tcp://192.168.99.102:2376 swarm-master v17.06.2-ce
swarm-node02 - virtualbox Running tcp://192.168.99.103:2376 swarm-master v17.06.2-ce查看集群信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58➜ zhichi eval $(docker-machine env --swarm swarm-master )
➜ zhichi docker info
Containers: 4
Running: 4
Paused: 0
Stopped: 0
Images: 3
Server Version: swarm/1.2.8
Role: primary
Strategy: spread
Filters: health, port, containerslots, dependency, affinity, constraint, whitelist
Nodes: 3
swarm-master: 192.168.99.101:2376
└ ID: J3GW:TQNR:DTPZ:OPKJ:KPLF:NPX2:W3LC:7S64:P75L:KDQX:DKJV:B6IG|192.168.99.101:2376
└ Status: Healthy
└ Containers: 2 (2 Running, 0 Paused, 0 Stopped)
└ Reserved CPUs: 0 / 1
└ Reserved Memory: 0 B / 1.021 GiB
└ Labels: kernelversion=4.4.86-boot2docker, operatingsystem=Boot2Docker 17.06.2-ce (TCL 7.2); HEAD : ff16afa - Wed Sep 6 00:17:25 UTC 2017, ostype=linux, provider=virtualbox, storagedriver=aufs
└ UpdatedAt: 2017-09-11T04:22:31Z
└ ServerVersion: 17.06.2-ce
swarm-node01: 192.168.99.102:2376
└ ID: XTQE:FRLO:WSUX:TTPG:ITGL:5USK:V2KV:2E4Y:TFWE:RT6K:ESFI:RW7S|192.168.99.102:2376
└ Status: Healthy
└ Containers: 1 (1 Running, 0 Paused, 0 Stopped)
└ Reserved CPUs: 0 / 1
└ Reserved Memory: 0 B / 1.021 GiB
└ Labels: kernelversion=4.4.86-boot2docker, operatingsystem=Boot2Docker 17.06.2-ce (TCL 7.2); HEAD : ff16afa - Wed Sep 6 00:17:25 UTC 2017, ostype=linux, provider=virtualbox, storagedriver=aufs
└ UpdatedAt: 2017-09-11T04:22:44Z
└ ServerVersion: 17.06.2-ce
swarm-node02: 192.168.99.103:2376
└ ID: 3QAJ:HBPZ:K52D:22WM:KF2F:6BMK:KEAN:BAOK:TSIK:G7Q3:MEJ5:MBGV|192.168.99.103:2376
└ Status: Healthy
└ Containers: 1 (1 Running, 0 Paused, 0 Stopped)
└ Reserved CPUs: 0 / 1
└ Reserved Memory: 0 B / 1.021 GiB
└ Labels: kernelversion=4.4.86-boot2docker, operatingsystem=Boot2Docker 17.06.2-ce (TCL 7.2); HEAD : ff16afa - Wed Sep 6 00:17:25 UTC 2017, ostype=linux, provider=virtualbox, storagedriver=aufs
└ UpdatedAt: 2017-09-11T04:22:47Z
└ ServerVersion: 17.06.2-ce
Plugins:
Volume:
Network:
Log:
Swarm:
NodeID:
Is Manager: false
Node Address:
Kernel Version: 4.4.86-boot2docker
Operating System: linux
Architecture: amd64
CPUs: 3
Total Memory: 3.063GiB
Name: e1e51c2e4f92
Docker Root Dir:
Debug Mode (client): false
Debug Mode (server): false
Experimental: false
Live Restore Enabled: false
以上操作只是为了让我们理解swarm集群的一些基本感念,是不能直接应用于生产环境的,至于直接应用于生产环境的集群部署,是我下面要做的!
- 本文作者: ChuLinx
- 本文链接: http://yoursite.com/2019/11/30/docker三剑客之docekr-swarm/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!