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

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

2016-09-09 10:06 881 查看
使用docker service create创建容器时默认会使用调度机制选择集群内的一个节点运行容器
如果希望创建的容器运行在指定的节点上可通过--constraint参数通过label来在指定的节点

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

命令参数说明:
[root@centos-minion2 ~]# dockerd --help| grep label
--label=[]     Set key=value labels to the daemon


例如我的配置 /etc/systemd/system/docker.service.d/docker.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock --insecure-registry 192.168.209.0/24 --label hostname=minion2
然后重启服务
[root@centos-minion2 ~]# systemctl daemon-reload
[root@centos-minion2 ~]# systemctl restart docker
在MANAGER 查看label
[root@centos-master ~]# docker node inspect -f '``.`Description`.`Engine`.`Labels`' centos-minion2
map[hostname:minion2]
第二步,创建service 指定在centos-minion2 这个节点上运行容器
[root@centos-master ~]# docker service create --name web --replicas 4 --constraint engine.labels.hostname==minion2 nginx



constraint后面的参数除了可以用==还可以用!=
之前的版本有支持表达式匹配,现在这个好像用不了,难道是打开方式不对?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  service create docker