這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
Docker Swarm manage命令的flStrategy選項用來指定scheduler調度的strategy的過濾項,其變數定義如下(cli/flags.go):
flStrategy = cli.StringFlag{ Name: "strategy", Usage: "placement strategy to use [" + strings.Join(strategy.List(), ", ") + "]", Value: strategy.List()[0],}
strategy的預設值是SpreadPlacementStrategy。
strategy在代碼中的實際定義是PlacementStrategy,一個interface:
// PlacementStrategy is the interface for a container placement strategy.type PlacementStrategy interface { // Name of the strategy Name() string // Initialize performs any initial configuration required by the strategy and returns // an error if one is encountered. // If no initial configuration is needed, this may be a no-op and return a nil error. Initialize() error // RankAndSort applies the strategy to a list of nodes and ranks them based // on the best fit given the container configuration. It returns a sorted // list of nodes (based on their ranks) or an error if there is no // available node on which to schedule the container. RankAndSort(config *cluster.ContainerConfig, nodes []*node.Node) ([]*node.Node, error)}
其中RankAndSort返回一個符合條件node(也就是Docker Engine)列表,列表中元素按匹配度排序。