- In a distributed application, different pieces of the app are called “services.”
- 面向服务的分布式系统架构设计(SOA)
- 若干个基于同一个image的Container instances,构成一个service
- A single container running in a service is called a task.
- 多个Services构成一个stack
- 使用docker-compose.yml 文件 定义一个stack
- 定义service(包括image、replicas、resources limits、ports、networks等)
- 提供load-balancing
- containers of all services will be distributed between nodes of a swarm
- 如果当前只有swarm中只有一个node,则所有container会集中在当前node上。
- 所有node,都可以暴露自己的IP地址、
- 并将请求通过轮询方式转发给同一个service下的所有container
- ingress routing mesh
- The reason all IP addresses work is that nodes in a swarm participate in an ingress routing mesh
- 但是注意:Keep in mind that in order to use the ingress network in the swarm, you need to have the following ports open between the swarm nodes before you enable swarm mode:
- * Port 7946 TCP/UDP for container network discovery.
- * Port 4789 UDP for the container ingress network.
- 一个swarm就是一个cluster
- 一个swarm中的machines分成两类:
- Swarm managers
- executes management commands
- the commands you execute will be on the swarm, rather than just on the current machine.
- and authenticates other machines to join the swarm as workers
- executes management commands
- workers
- only swarm managers execute Docker commands; workers are just for capacity(容量)
- Swarm managers
- Swarm initialized
- 运行命令docker swarm init --advertise-addr <network interface ip>,
- 会将current node 设置为 a swarm manager
- 运行命令docker swarm init --advertise-addr <network interface ip>,
- add a worker to this swarm
- add a manager to this swarm
- 参考Swarm initialized的时候的输出信息
- 让当前node Leaving a swarm
- 运行命令docker swarm leave
- deploy a stack
- docker swarm (蜂群)init
- stack运行在swarm mode下。。所以必须首先启动swarm mode
- docker stack deploy -c docker-compose.yml {stack_name}
- docker stack deploy就是一个多级命令
- 自动生成service_name、network_name
- docker swarm (蜂群)init
- 移除stack
- docker stack rm {stack_name}
- 动态扩展(scale)stack
- changing settings(比如replicas) in docker-compose.yml,
- saving the change,
- and re-running the docker stack deploy command
- Always run docker swarm init and docker swarm join with port 2377
- or no port at all and let it take the default.
- 因为它是the swarm management port,
- port 2376, which is the Docker daemon port.
- A stack is a group of interrelated(有关系的) services
- that share dependencies, and can be orchestrated(编排) and scaled together
- 添加多个service
- add services to our docker-compose.yml file
- 注意几个定义选项
- a volumes key,
- 授权当前service提供访问host machine上的某些文件/目录(绝对路径)
- 注意文件路径不对,可能引发错误。
- 使用docker stack ps --no-trunc {stack_name},查看ERROR列信息来调试
- a placement key,
- ensuring that this service only ever runs on a swarm manager – never a worker.
- command
- service启动的时候,执行的命令行命令??
- a volumes key,
- 两个image:
- dockersamples/visualizer:stable
- displays Docker services running on a swarm in a diagram.
- redis
- Redis has an official image in the Docker library and has been granted the short image name of just redis, so no username/repo notation here
- dockersamples/visualizer:stable