【问题标题】:Docker-compose having problems with labelsDocker-compose 有标签问题
【发布时间】:2017-11-03 11:15:47
【问题描述】:

我正在尝试使用他们文档中显示的示例设置Traefik 反向代理。当我尝试启动“whoami”服务时,出现以下错误:

Creating test_whoami_1 ... 

ERROR: for test_whoami_1  dictionary update sequence element #0 has length 22; 2 is required

ERROR: for whoami  dictionary update sequence element #0 has length 22; 2 is required
Traceback (most recent call last):
  File "bin/docker-compose", line 6, in <module>
  File "compose/cli/main.py", line 68, in main
  File "compose/cli/main.py", line 121, in perform_command
  File "compose/cli/main.py", line 952, in up
  File "compose/project.py", line 455, in up
  File "compose/parallel.py", line 70, in parallel_execute
ValueError: dictionary update sequence element #0 has length 22; 2 is required
Failed to execute script docker-compose

示例 docker-compose.yml 可以在 Traefik 文档中找到: 测试/docker-compose.yml

version: '3.3'

services:
  whoami:
    image: emilevauge/whoami
    networks:
      - web
    labels:
      - "traefik.backend=whoami"
      - "traefik.frontend.rule=Host:whoami.docker.localhost"

networks:
  web:
    external:
      name: traefik_webgateway

traefik/docker-compose.yml

version: '3.3'

services:
  proxy:
    image: traefik:1.4.1
    restart: always
    ports:
      - 80:80
      - 8080:8080
    command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "./traefik.toml:/traefik.toml"
    container_name: traefik

networks:
  webgateway:
    driver: bridge

使用以下 docker 和 docker-compose 版本:

Docker version 17.09.0-ce, build afdb6d4
docker-compose version 1.17.0, build ac53b73

【问题讨论】:

    标签: docker docker-compose traefik


    【解决方案1】:

    解决方案:降级到 docker-compose v1.16.1。

    【讨论】:

    • 我可以确认这在 1.16.1 中有效。但是为什么这在 1.17 中不起作用。你能解释一下吗?
    • 抱歉,我还没有找到解释究竟是什么导致了 1.17.0 上的问题。
    【解决方案2】:

    Docker compose 标签包含在版本 v3.3 中,您正在运行版本 1.17.0

    请参阅doc 了解更多信息。

    【讨论】:

    • docker-compose 1.17.0 是最新版本:github.com/docker/compose/releases 另外,我尝试将 docker-compose.yml 的版本更改为版本:'3.3',但没有成功。
    • 我把语法改成了这种风格:`labels: traefik.backend: "portainer" ` from `labels: - "traefik.backend=portainer" ` 它对我有用
    【解决方案3】:

    我确认 metanerd 的回答:

    使用

    labels:
      traefik.backend: "whoami"
      traefik.frontend.rule: "Host:whoami.docker.localhost"
    

    有效。

    【讨论】:

      【解决方案4】:

      我相信,在 3.3 中,您将标签放在 build 属性下 例如见下文

      version: '3.3'
      services:
        sample-app:
          image: ${IMAGE_NAME}
          build:
            context: .
            labels:
              org.label-schema.build-date: ${BUILD_DATE}
              org.label-schema.commit: ${COMMIT}
      ...
      

      您可以从 docker inspect 中看到,标签已被应用

      docker inspect --format='{{json .Config.Labels}}' blah/sample-app
      
      {"org.label-schema.build-date":"2019-05-24-10-36-22","org.label-schema.commit":"2cc11a2"}
      

      https://docs.docker.com/compose/compose-file/

      【讨论】:

      • 它们也可以在运行时级别(容器与图像)。确保您的文件“版本”>= '3.3'。
      【解决方案5】:

      升级你的 docker 和 docker-compose 两者。它会自动修复。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-07-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多