0

我已经尝试了所有方法,但无法运行 exec 类型的作业。我在 3 个不同的集群上尝试过,但都失败了。

该作业修剪 docker 容器并仅运行 docker system prune -a

这是配置部分:

driver = "exec"
config {
  command = "bash"
  args = ["-c",
  " docker system prune -a "]
}

没有日志和容器不被修剪:

job "docker-cleanup" {
  type = "system"
  constraint {
    attribute = "${attr.kernel.name}"
    operator  = "="
    value     = "linux"
  }
  datacenters = ["dc1"]
  group "docker-cleanup" {

    restart {
      interval = "24h"
      attempts = 0
      mode     = "fail"
    }
    task "docker-system-prune" {
      driver = "exec"
      config {
        command = "bash"
        args = ["-c",
        " docker system prune -a "]
      }
      resources {
        cpu    = 100
        memory = 50
        network {
          mbits = 1
        }
      }
    }
  }
}

我究竟做错了什么?

4

2 回答 2

0

据我所知,所有参数都应单独提供:

driver = "exec"
config {
  command = "/bin/bash"
  args = [
    "-c", "docker", "system", "prune", -a "
  ]
}
于 2021-08-06T15:10:14.530 回答
0

我建议您提供输出以使其更易于分析。

您可以尝试的一件事是将完整路径添加到 bash 可执行文件。

   driver = "exec"
    config {
      command = "/bin/bash"
      args = ["-c",
      " docker system prune -a "]
    }

此外,您缺少系统修剪上的“--force”参数,没有它 - docker system prune 要求确认。

docker system prune --all --force
于 2020-05-29T04:42:33.493 回答