Docker1.12 swarm模式下让容器在指定节点运行

使用docker service create建立容器时默认会使用调度机制选择集群内的一个节点运行容器node

若是但愿建立的容器运行在指定的节点上可经过--constraint参数经过label来在指定的节点nginx


第一步,在节点启动的docker daemon加上--labelweb


命令参数说明:docker

[root@centos-minion2 ~]# dockerd --help| grep label
  --label=[]     Set key=value labels to the daemon


例如个人配置 /etc/systemd/system/docker.service.d/docker.confcentos

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock --insecure-registry 192.168.209.0/24 --label hostname=minion2

而后重启服务bash

[root@centos-minion2 ~]# systemctl daemon-reload
[root@centos-minion2 ~]# systemctl restart docker

在MANAGER 查看labelide

[root@centos-master ~]# docker node inspect -f '``.`Description`.`Engine`.`Labels`' centos-minion2
map[hostname:minion2]

第二步,建立service 指定在centos-minion2 这个节点上运行容器unix

[root@centos-master ~]# docker service create --name web --replicas 4 --constraint engine.labels.hostname==minion2 nginx

wKiom1fSGOKg5zbzAAOB9yeIgw0654.jpg

constraint后面的参数除了能够用==还能够用!=rest

以前的版本有支持表达式匹配,如今这个好像用不了,难道是打开方式不对?blog

相关文章
相关标签/搜索