简体   繁体   English

在docker-compose文件中指定服务标签

[英]Specify service label in docker-compose file

When labeling a service in the docker-compose file only the created container is labeled and not the service itself. 在docker-compose文件中标记服务时,只会标记创建的容器,而不会标记服务本身。

I would like to add a label to a service created using a docker-compose file. 我想为使用docker-compose文件创建的服务添加标签。 When adding the label under the labels property, the label is only added to the corresponding container and not to the service itself. 在标签属性下添加标签时,标签仅添加到相应的容器中,而不添加到服务本身。

In the documentation of the docker service create command there are two different options for labels: 在docker service create命令的文档中,标签有两个不同的选项:

  • --container-label: specify container label --container-label:指定容器标签
  • --label: specify service label --label:指定服务标签

I'm wondering why the label property in the docker-compose file only corresponds to the first option. 我想知道为什么docker-compose文件中的label属性仅对应于第一个选项。

version: "3.7"

services:
  zalenium:
    image: zalenium:latest
    hostname: zalenium
    deploy:
      placement:
        constraints:
            - node.role == manager
    labels:
        - "de.zalando.gridRole=hub"
    ports:
        - "4444:4444"
    networks:
        - zalenium
    environment:
        - PULL_SELENIUM_IMAGE=true
        - ZALENIUM_PROXY_CLEANUP_TIMEOUT=1800
    command: ["start", "--swarmOverlayNetwork", "tau_zalenium", "--videoRecordingEnabled", "false"]

networks:
    zalenium:
        driver: overlay
        attachable: true

Actual result: Only the created container has the label "de.zalando.gridRole" 实际结果:只有创建的容器具有标签“ de.zalando.gridRole”

Expected result: The service should have the label "de.zalando.gridRole" 预期结果:服务应具有标签“ de.zalando.gridRole”

According to the docker-compose reference, you need to specify the service labels like this: 根据docker-compose参考,您需要指定服务标签,如下所示:

version: "3.7"
services:
  web:
    image: web
    deploy:
      labels:
        com.example.description: "This label will appear on the web service"

Add a deploy section and mention your labels there. 添加一个部署部分,并在其中提及您的标签。

As with docker, here as well these labels are taken into account when deploying on a docker swarm. 与docker一样,在docker swarm上进行部署时,也会考虑这些标签。 Otherwise they are ignored. 否则,它们将被忽略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM