gpt4 book ai didi

docker - 如何通过 echo 命令向 mac 控制台发送消息? (适用于 Mac 的 docker )

转载 作者:行者123 更新时间:2023-12-02 19:36:25 25 4
gpt4 key购买 nike

我在 Docker for Mac 上使用 Node 服务器容器。node.js 服务器的消息显示在我的 mac 控制台上。

如何在我的 Mac 控制台上通过容器内部的 bash 脚本显示消息?我也在运行 shell 脚本。我想通过 echo something

显示一些消息

我的docker-compose包含healthcheck,echo是在healthcheck.sh里面执行的:

healthcheck: test: ["CMD", "bash", "-c", "/xxx/xxxx/healthcheck.sh"]

谢谢!

最佳答案

由于您的 echo 在 docker healthcheck 中执行,其输出不会发送到容器 stdout。 Docker 将健康检查输出存储为容器元数据:

To help debug failing probes, any output text (UTF-8 encoded) that the command writes to stdout or stderr will be stored in the health status and can be queried with docker inspect. Such output should be kept short (only the first 4096 bytes are stored currently).

https://docs.docker.com/engine/reference/builder/#healthcheck

所以你可以使用这个看到输出:

docker inspect <container-id>

看起来像:

        "Health": {
"Status": "unhealthy",
"FailingStreak": 6,
"Log": [
{
"Start": "2017-06-17T19:39:33.001296235Z",
"End": "2017-06-17T19:39:33.059073965Z",
"ExitCode": 1,
"Output": "/bin/sh: 1: curl: not found\n"
},

更具体地说:

docker inspect <container-id> -f '{{index .State.Health.Log 0}}'

关于docker - 如何通过 echo 命令向 mac 控制台发送消息? (适用于 Mac 的 docker ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44603751/

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