您的位置:首页 > 运维架构 > Docker

Docker container/service/stack/swarm

2018-03-16 14:59 246 查看
In a distributed application, different pieces of the app are called “services.”面向服务的分布式系统架构设计(SOA)

若干个基于同一个image的Container instances,构成一个serviceA single container running in a service is called a task.

多个Services构成一个stack
使用docker-compose.yml 文件 定义一个stack定义service(包括image、replicas、resources limits、ports、networks等)

提供load-balancingcontainers of all services  will be distributed between nodes of a swarm
如果当前只有swarm中只有一个node,则所有container会集中在当前node上。
所有node,都可以暴露自己的IP地址、并将请求通过轮询方式转发给同一个service下的所有container
ingress routing meshThe 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 managersexecutes 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

workersonly swarm managers  execute Docker commands; workers are just for capacity(容量)

Swarm initialized运行命令docker swarm init --advertise-addr <network interface ip>,会将current node 设置为 a swarm manager

add a worker to this swarm
add a manager to this swarm参考Swarm initialized的时候的输出信息

让当前node Leaving a swarm运行命令docker swarm leave

deploy a stackdocker swarm (蜂群)initstack运行在swarm mode下。。所以必须首先启动swarm mode

docker stack deploy -c docker-compose.yml {stack_name}docker stack deploy就是一个多级命令

自动生成service_name、network_name

移除stackdocker stack rm {stack_name}

动态扩展(scale)stackchanging 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

添加多个serviceadd 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.

commandservice启动的时候,执行的命令行命令??

两个image:dockersamples/visualizer:stabledisplays Docker services running on a swarm in a diagram.

redisRedis 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: