Docker container/service/stack/swarm


  • 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
    • workers
      • only 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 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
  • 移除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启动的时候,执行的命令行命令??

  • 两个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





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值