在单个 fargate 任务中运行多个容器以进行 clair 容器扫描

问题描述

我们在同一个 fargate 任务中运行 clairclair-db 容器。以下是我们任务定义的片段。

{
    "family": "clair","networkMode": "awsvpc","containerDeFinitions": [
        {
            "name": "db","image": "<REPO_URL>/clairdb:v1.0","essential": true,"command": [
                "sh","-c","echo clair db runs"
            ],"portMappings": [
                {
                    "containerPort": 5432,"hostPort": 5432,"protocol": "tcp"
                }
            ],},{
            "name": "clair","image": "<REPO_URL>/clair:v1.0","echo clair runs"
            ],"portMappings": [
                {
                    "containerPort": 6060,"hostPort": 6060,

根据

enter image description here

localhost 可用于在 awsvpc 模式下在单个任务的这两个容器之间进行通信。我们在 Clair config.yaml

中给出了以下选项
clair:
  database:
    type: pgsql
    options:
      source: host=localhost port=5432 user=postgres password=xxxx sslmode=disable statement_timeout=60000

因此,理想情况下,clair 应该能够链接到在同一网络上的 clair-db 上运行的 localhost:5432 容器。 Clair-db 容器在 fargate 中运行良好,但 clair 容器失败并显示以下日志:

{"Event":"pgsql: Could not open database: dial tcp 127.0.0.1:5432: connect: connection refused","Level":"fatal","Location":"main.go:97","Time":"2021-03-23 13:26:38.737437"}

在 docker 术语中,这就是我们如何链接这两个容器:

docker run -p 5432:5432 -d --name db arminc/clair-db:2017-05-05
docker run -p 6060:6060 --link db:postgres -d --name clair arminc/clair-local-scan:v2.0.0-rc.0

我们在这里遗漏了什么吗?知道为什么与 localhost 的连接在 clair 的 fargate 容器中不起作用吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)