使用AWS ECS和Fargate时如何告诉Traefik不要尝试连接到docker.sock

时间:2019-09-13 06:20:36

标签: amazon-ecs traefik aws-fargate

我正在使用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 Provider时,它不需要连接到套接字。因此它仍然尝试。


traefik.toml

[entryPoints]
  ...

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

[retry]

docker-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的方法。

1 个答案:

答案 0 :(得分:1)

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

此行是早期简单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
      ...

...

因此,如果有人遇到同样的愚蠢问题,我希望这个独白会有所帮助。