docker-compose 部署确保容器安装在特定服务器上

docker-compose deployment ensure container is installed on specific server

我的撰写文件中有以下内容:

  postgres:
    deploy:
      mode: global
      placement:
        constraints:
          - node.labels.server == data

我的节点在检查时有以下内容:

"Spec": {
    "Labels": {
        "server": "data"
    },
    "Role": "worker",
    "Availability": "active"
},

但是,当我部署我的堆栈时,postgres 没有安装在任何地方...

我错过了什么?

[更新]

这是在 docker-compose.prod.yml 顺便说一下,如果您想知道其余配置在哪里

[更新]

这是运行将我的组合作为跨多个服务器的堆栈。使用此命令将其关闭:

docker stack deploy --compose-file docker-compose.yml --compose-file docker-compose.prod.yml stackname--with-registry-auth

这是 ps 的输出:

root@sonatribe-1:~# docker service ps postgres --no-trunc
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE       ERROR               PORTS

在其他服务的其他地方,我有这样的东西来确保某些东西 运行 在管理器节点上:

deploy:
  mode: global
  placement:
    constraints:
      - node.role == manager

而且效果很好 - 只有一个使用:

node.labels.server == data

那不行

这对我有用,所以我会逐步检查它,看看您这边是否遗漏了什么:

我创建了一个三节点群,只有一个管理器:

docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
diewo1v4bf2149fx422guh8ci *   dvc1                Ready               Active              Leader              18.06.1-ce
jlz2sbman8wz7sukcs41jng1n     dvc2                Ready               Active                                  18.06.1-ce
g7kocy0qo76m42o80phr6poh4     dvc3                Ready               Active                                  18.06.1-ce

我给节点3添加标签:

docker node update dvc3 --label-add server=data

docker 节点检查 dvc3:

"Spec": {
            "Labels": {
                "server": "data"
            },
            "Role": "worker",
            "Availability": "active"
        },

我有一个合成文件stack.yml:

version: '3.7'

services:
  nginx:
    image: nginx:alpine
    deploy:
      mode: global
      placement:
        constraints:
          - node.labels.server == data

我部署堆栈:

docker stack deploy -c stack.yml test

我也在 dvc1 上 运行ning docker events 显示:

2018-09-15T23:50:49.608191542-04:00 network create yf21vjsbjpcnastxugnp3dax5 (name=test_default)
2018-09-15T23:50:49.609334207-04:00 network update yf21vjsbjpcnastxugnp3dax5 (name=test_default)
2018-09-15T23:50:49.609992316-04:00 node update diewo1v4bf2149fx422guh8ci (name=dvc1)
2018-09-15T23:50:49.610052739-04:00 node update g7kocy0qo76m42o80phr6poh4 (name=dvc3)
2018-09-15T23:50:49.610086383-04:00 node update jlz2sbman8wz7sukcs41jng1n (name=dvc2)
2018-09-15T23:50:50.067716009-04:00 service create xjgwq14ot13r1olzcsatd2ktb (name=test_nginx)
2018-09-15T23:50:50.119799354-04:00 service update xjgwq14ot13r1olzcsatd2ktb (name=test_nginx)

我应该在 dvc3 上也有 运行 事件,所以我捕获了任务创建(它只会显示在获取它的节点上)。

让我们检查堆栈和任务:

docker service ls

ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
xjgwq14ot13r        test_nginx          global              1/1                 nginx:alpine

docker node ps dvc3
ID                  NAME                                   IMAGE               NODE                DESIRED STATE       CURRENT STATE                ERROR               PORTS
w1i3fpwfy88c        test_nginx.g7kocy0qo76m42o80phr6poh4   nginx:alpine        dvc3                Running             Running about a minute ago

希望对您有所帮助,您能否将您的解决方案简化为该示例,看看它是否有效?