首页 > 解决方案 > 如何告诉 Traefik 在使用 AWS ECS 和 Fargate 时不要尝试连接到 docker.sock

问题描述

我正在使用 Fargate 在 AWS ECS 上为 Web 应用程序设置环境。安装程序使用多个容器作为前端和后端,并使用 Traefik(也在一个容器中)在 ALB 后面进行路由。我正在使用 ecs-cli 和 docker-compose 文件进行部署,一切正常。

尽管一切正常,但 traefik 容器仍在不断记录有关无法连接到 docker.sock 的错误

time="2019-09-12T21:54:13Z" level=error msg="Failed to retrieve information of the docker client and server host: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"
time="2019-09-12T21:54:13Z" level=error msg="Provider connection error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?, retrying in 3.829225701s"

我非常了解 traefik 将无法在该环境中连接到 docker.sock,并且当我显然正确配置了ECS 提供程序时,它不需要连接到套接字。因此它仍然尝试。


traefik.toml

[entryPoints]
  ...

[ecs]
clusters = ["cluster-name"]
watch = true
refreshSeconds = 15
exposedByDefault = true
region = "eu-west-1"
domain = "ecs.domain"

[retry]

码头工人-comopse.yml

version: "3"
services:
  proxy:
    image: ${custom-image-with-toml-baked-in}
    command: --api --docker
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    labels:
      - "traefik.enable=true"
      - "traefik.backend=traefik"
      - "traefik.frontend.rule=Host:traefik.ecs.domain"
      - "traefik.port=8080"
    logging:
      driver: awslogs
      ...

...

因此,正如我所提到的,看起来 Traefik 仍想连接到 docker.sock,而我无法找到告诉 Traefik 仅依赖 ECS 的方法。

标签: amazon-ecstraefikaws-fargate

解决方案


因此,在查看我的问题时,我仔细检查了command: --api --dockerdocker-compose 文件中的行,结果发现错误来自--docker选项...

此行是早期简单 docker 部署的遗留内容,因此删除此选项对我有用。

码头工人-compose.yml

version: "3"
services:
  proxy:
    image: ${custom-image-with-toml-baked-in}
    command: --api
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    labels:
      - "traefik.enable=true"
      - "traefik.backend=traefik"
      - "traefik.frontend.rule=Host:traefik.ecs.domain"
      - "traefik.port=8080"
    logging:
      driver: awslogs
      ...

...

所以万一有人遇到同样愚蠢的问题,我希望这个独白能有所帮助。


推荐阅读