> For the complete documentation index, see [llms.txt](https://camelgemonion.gitbook.io/docker/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://camelgemonion.gitbook.io/docker/dockercompose.yaml-wen-jian-zhong-chang-yong-zhi-ling/untitled-12/healthcheck.md).

# healthcheck

配置一个检查，来确定运行服务的容器状态是否为`healthy`。

```
healthcheck:
  test: ["CMD", "curl", "-f", "http://localhost"]
  interval: 1m30s
  timeout: 10s
  retries: 3
  start_period: 40s
```

`interval`, `timeout`和`start_period`指定为持续时间。

test必须是一个字符串或列表。如果是列表，第一个元素必须是`NONE`，`CMD`或`CMD-SHELL`。如果是字符串，则等同于下面通过字符串指定的`CMD-SHELL`。

```
# Hit the local web app
test: ["CMD", "curl", "-f", "http://localhost"]
```

如上所述，但是被包裹在`/bin/sh` 中。下面两种形式是相等的。

```
test: ["CMD-SHELL", "curl -f http://localhost || exit 1"]
```

```
test: curl -f https://localhost || exit 1
```

如果要禁用默认健康检查的设置，可以使用`disable: true`。这等同于`test: ["NONE"]`。
