Error response from daemon: rpc error: code = InvalidArgument desc = only updates to Labels are allowed

Error response from daemon: rpc error: code = InvalidArgument desc = only updates to Labels are allowed

我有

Error response from daemon: rpc error: code = InvalidArgument desc = only updates to Labels are allowed

重新部署堆栈时

docker stack deploy -c docker-compose.yml --with-registry-auth monitoring

https://github.com/moby/moby/issues/35048

更新配置的唯一方法是删除堆栈并重新部署它

docker stack rm <my_stack_name>
docker stack deploy -c docker-compose.yml --with-registry-auth <my_stack_name>

不幸的是,正如 Ryabchenko Alexander 所说,docker 配置无法更新,see moby issue

在一种方法中,您可以使用命令 docker service rm service_name.

删除使用新配置的服务

然后使用 docker config rm config_name 删除配置并重新部署堆栈以更新配置并重新创建删除的服务。

更新:如果需要不停机,请参阅this comment

您还可以发布一个新的 conf,在名称中对其进行版本控制。

我使用 yml 文件来部署和更新堆栈。如果我更改一个 conf 文件,我会在 yml 文件中重命名引用(即从 conf-v1conf-v2)并再次部署:docker 创建一个新的 conf 并引用它。

优点:

  • 没有标签错误
  • 如果部署失败,docker 自动回滚是最安全的(我想,如果 conf-v2 有重大更改,回滚会使堆栈再次引用 conf-v1

缺点:

  • 很多 conf 要删除

建议的删除stack/service方法带来停机时间

幸运的是,有一个无需停机即可解决此问题的棘手解决方法。只需为 config/secret 设置一个名称,并在每次 运行 docker stack deploy 命令时借助环境变量更改该名称:

version: '3.7'
services:
  nginx:
    image: nginx:alpine
    configs:
      - source: nginxconf
        target: /etc/nginx/foobar.conf
configs:
  nginxconf:
    name: nginx.conf-${CONFIG_VERSION:-0}
    file: ./nginx.conf

对于下一次部署,首先更改该变量,然后 运行 docker stack deploy:

CONFIG_VERSION=1 docker stack deploy -c docker-compose.yml mystack

您可以阅读更多内容here