Docker从v1.12.0后开始集成swarm mode(swarmkit),关于swarm的所有操作可以直接使用docker
swarm 命令来完成。Docker
Swarm是docker原生的用于管理docker集群的工具,内置kv存储功能,不再需要外置的etcd,目前的功能主要有:
a. Docker节点集群的管理,包括集群的创建,master,worker节点的加入删除。
b. 服务的管理,包括service的创建删除,update,scale等。
c. 跨主机的网络管理(overlay)
d. 服务发现(内建DNS服务,服务可以通过dns发现)
e. 服务负载均衡LB(端口暴露routing meshing, VIP, DNS-round-robin)
Docker Swarm Mode和Swarm是有区别的,虽然都是集群管理服务编排工具。
#docker swarm init --advertise-addr 192.168.56.102Swarm initialized: current node (dcpp5zxdh35g2du00q1pvhtc2) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-4sqil7es18zvthb0s7cjdtpwe1q1fkw0m6jeikh30e70sal0sb \
-dj34fdb8w9v0k0u5cege14ty0 \
192.168.56.102:2377
To add a manager to this swarm, run 'docker swarm join-token manager' \
and follow the instructions. 初始化后默认输出的信息为worker 工作节点加入方式,在工作节点执行,就可以将节点加入到集群
如下命令可以查看manager 管理节点加入方式,要在管理节点执行才有效
#docker swarm join-token managerTo add a manager to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-4sqil7es18zvthb0s7cjdtpwe1q1fkw0m6jeikh30e70sal0sb \
-4gqw9f7fdylqcxwfz07jq8bfs \
192.168.56.102:2377
#192.168.56.103
将103 做为管理节点加入集群
#docker swarm join \
--token SWMTKN-1-4sqil7es18zvthb0s7cjdtpwe1q1fkw0m6jeikh30e70sal0sb \
-dj34fdb8w9v0k0u5cege14ty0 \
192.168.56.102:2377This node joined a swarm as a worker.
#192.168.56.104
将104 做为管理节点加入集群
#docker swarm join \
--token SWMTKN-1-4sqil7es18zvthb0s7cjdtpwe1q1fkw0m6jeikh30e70sal0sb \
-dj34fdb8w9v0k0u5cege14ty0 \
192.168.56.102:2377This node joined a swarm as a worker.
在管理节点执行节点查看命令,可看到个节点的状态
#docker node lsID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
dcpp5zxdh35g2du00q1pvhtc2 manager1 Ready Active Leader
sxkcz3xhjyuks0gwtb22h6q0t worker1 Ready Active
w8d2dbp7l3j6df6r0v3feuscq * mangger2 Ready Active Reachable 三台主机的集群,到这就算创建完了,后续是网络和管理节点发出指令
OptionRequiredDescriptiontypes
The type of mount, can be either volume, bind, or tmpfs. Defaults to volume if no type is specified.
volume: mounts a [managed volume](volume_create.md) into the container.
bind: bind-mounts a directory or file from the host into the container.
tmpfs: mount a tmpfs in the container
src or sourcefor type=bind only>
type=volume: src is an optional way to specify the name of the volume (for example, src=my-volume). If the named volume does not exist, it is automatically created. If no src is specified, the volume is assigned a random name which is guaranteed to be unique on the host, but may not be unique cluster-wide. A randomly-named volume has the same lifecycle as its container and is destroyed when the container is destroyed (which is upon service update, or when scaling or re-balancing the service)
type=bind: src is required, and specifies an absolute path to the file or directory to bind-mount (for example, src=/path/on/host/). An error is produced if the file or directory does not exist.
type=tmpfs: src is not supported.
dst or destination or target
yes Mount path inside the container, for example /some/path/in/container/. If the path does not exist in the container's filesystem, the Engine creates a directory at the specified location before mounting the volume or bind-mount. readonly or ro
The Engine mounts binds and volumes read-write unless readonly option is given when mounting the bind or volume.
true or 1 or no value: Mounts the bind or volume read-only.