Docker Swarm - 策略似乎没有任何效果

时间:2016-05-09 10:36:21

标签: docker docker-swarm

我已经使用Docker Machine配置了swarm master和swarm节点(如here所述)。一切都很好;所有机器都已创建并运行,它们都已被发现并接受容器。

来自#docker-machine ls'的输出。是:

$ docker-machine ls
NAME         ACTIVE      DRIVER         STATE     URL                          SWARM               DOCKER    ERRORS
default      -           virtualbox     Stopped                                                    Unknown   
local        -           virtualbox     Stopped                                                    Unknown   
my-swarm     * (swarm)   digitalocean   Running   tcp://104.131.161.197:2376   my-swarm (master)   v1.11.1   
node0        -           digitalocean   Running   tcp://104.236.29.169:2376    my-swarm            v1.11.1   
node1        -           digitalocean   Running   tcp://104.236.216.164:2376   my-swarm            v1.11.1   

我遇到的问题是容器的分配。无论我为swarm设置了哪种策略,它似乎只能一次将容器分配给其中一个节点。即我运行了一堆容器,并且都在同一节点上启动,如下所示(使用策略Spread):

$ docker ps
5c075d7ccddc        stress              "/bin/sh -c /stress.s"   32 seconds ago       Up 31 seconds                           node0/elated_goldstine
5bae22a15829        stress              "/bin/sh -c /stress.s"   46 seconds ago       Up 44 seconds                           node0/cocky_booth
dc52b3dfa0e6        stress              "/bin/sh -c /stress.s"   About a minute ago   Up About a minute                       node0/goofy_kalam
3b9e69c694da        stress              "/bin/sh -c /stress.s"   About a minute ago   Up About a minute                       node0/focused_fermat
ef0e006ff3e0        stress              "/bin/sh -c /stress.s"   About a minute ago   Up About a minute                       node0/stoic_engelbart
53e46b19ab33        stress              "/bin/sh -c /stress.s"   About a minute ago   Up About a minute                       node0/condescending_rosalind
e9e126c7f4c6        stress              "/bin/sh -c /stress.s"   About a minute ago   Up About a minute                       node0/sleepy_jang
f9c0003d509d        stress              "/bin/sh -c /stress.s"   About a minute ago   Up About a minute                       node0/amazing_bhaskara

我期望的是容器大致均匀地分布在3个节点上,特别是因为我在容器中运行的脚本被设计为尽可能多地占用CPU。但是所有这些都在node0上(我只能期望使用Binpack)。随机策略具有完全相同的行为。

来自'泊坞广告信息'的输出将swarm master设置为active似乎是正确的:

$ docker info
Containers: 15
 Running: 4
 Paused: 0
 Stopped: 11
Images: 5
Server Version: swarm/1.2.1
Role: primary
Strategy: spread
Filters: health, port, containerslots, dependency, affinity, constraint
Nodes: 3 
 my-swarm: 104.131.161.197:2376
  └ ID: L2HK:F6S3:WWIM:BHNI:M4XL:KLEA:4U22:J6CE:ZHZI:OGGT:76KF:MTQU
  └ Status: Healthy
  └ Containers: 2
  └ Reserved CPUs: 0 / 1
  └ Reserved Memory: 0 B / 513.4 MiB
  └ Labels: executiondriver=, kernelversion=4.2.0-27-generic, operatingsystem=Ubuntu 15.10, provider=digitalocean, storagedriver=aufs
  └ Error: (none)
  └ UpdatedAt: 2016-05-09T10:25:24Z
  └ ServerVersion: 1.11.1
 node0: 104.236.29.169:2376
  └ ID: I3TQ:5BMS:TM2P:GLL4:64OH:BDMY:SWBU:3QG4:TOZ2:LEDW:A6SQ:X34H
  └ Status: Healthy
  └ Containers: 12
  └ Reserved CPUs: 0 / 1
  └ Reserved Memory: 0 B / 513.4 MiB
  └ Labels: executiondriver=, kernelversion=4.2.0-27-generic, operatingsystem=Ubuntu 15.10, provider=digitalocean, storagedriver=aufs
  └ Error: (none)
  └ UpdatedAt: 2016-05-09T10:25:02Z
  └ ServerVersion: 1.11.1
 node1: 104.236.216.164:2376
  └ ID: OTQH:UBSV:2HKE:ZVHL:2K7Z:BYGC:ZX25:Y6BQ:BN5J:UWEB:65KE:DABM
  └ Status: Healthy
  └ Containers: 1
  └ Reserved CPUs: 0 / 1
  └ Reserved Memory: 0 B / 513.4 MiB
  └ Labels: executiondriver=, kernelversion=4.2.0-27-generic, operatingsystem=Ubuntu 15.10, provider=digitalocean, storagedriver=aufs
  └ Error: (none)
  └ UpdatedAt: 2016-05-09T10:25:10Z
  └ ServerVersion: 1.11.1
Plugins: 
 Volume: 
 Network: 
Kernel Version: 4.2.0-27-generic
Operating System: linux
Architecture: amd64
CPUs: 3
Total Memory: 1.504 GiB
Name: my-swarm
Docker Root Dir: 
Debug mode (client): false
Debug mode (server): false
WARNING: No kernel memory limit support

是否有一些我错过的,这种类型的自动发布必须以我期待的方式工作?

1 个答案:

答案 0 :(得分:0)

问题

您的Docker Agent很可能没有尝试在其上运行的映像。

请注意,每个Docker代理上swarm buildswarm pull都不会buildpull

解决方案A

在每个Docker代理上手动运行pull

解决方案B (未测试)

运行本地Docker registry,其中Docker代理将从中提取图像。

玩Swarm玩得开心!另外,如果可以的话,我建议你阅读this answer,其中详细介绍了关于Swarm的整个分步教程。