gpt4 book ai didi

docker - 如何从docker-compose文件中查看容器的容器健康状态

转载 作者:行者123 更新时间:2023-12-02 20:49:45 29 4
gpt4 key购买 nike

从docker-compose 1.10.0 there is support for health checks开始。我开始在我的docker-compose文件之一中实现这些功能。

有几个建议从docker ps查看容器健康状态的站点。见下文。

但是,运行docker ps时我看不到任何健康状况。我的docker-compose文件的摘录如下:

version: "2.1"

services:

my-service:
container_name: my-service
image: "our-registry:5000/my-service:1.0.1"
expose: [3000]
restart: always
depends_on:
- other-service-1
- other-service-2
healthcheck:
test: ["nc", "-z", "127.0.0.1", "3000", "||", "exit", "1"]
interval: "2s"
timeout: "1

我的 docker ps输出的摘录如下:
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
af680b9fc6c3 our-registry/pr-georegion:1.0.1 "node index.js" 8 minutes ago Up 8 minutes 3000/tcp pr-georegion

Docker和docker-compose版本:
# docker -v
Docker version 1.12.6, build 78d1802
# docker-compose -v
docker-compose version 1.10.1, build b252738

Example 1

Example 1

Example 2

enter image description here

最佳答案

我在docker-compose文件中发现了问题。来自[官方文档](测试必须为字符串或列表。如果为列表,则第一项必须为NONE,CMD或CMD-SHELL。如果为字符串,则等效于指定CMD-SHELL后跟该字符串。):

test must be either a string or a list. If it’s a list, the first item must be either NONE, CMD or CMD-SHELL. If it’s a string, it’s equivalent to specifying CMD-SHELL followed by that string.



所以我改变了:
test: ["nc", "-z", "127.0.0.1", "3000", "||", "exit", "1"]

对于:
test: ["CMD-SHELL", "nc -z 127.0.0.1 3000 || exit 1"]

关于docker - 如何从docker-compose文件中查看容器的容器健康状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42023837/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com