docker { logs } returns no lines for containers that log to stderr

未关闭 适合新手
#2,150 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
docker, typescript
领域
backend

调研方向

从 api/src/unraid-api/graph/resolvers/docker/docker-log.service.ts 中的 DockerLogService.getContainerLogs 开始。issue 指出,目前只从 docker 命令读取 stdout。检查 resolver 如何解析和排序带时间戳的行,然后验证查询也会返回 stderr 输出,包括使用仅输出到 stderr 的容器进行的给定复现。

由索引模型根据 Issue 内容生成。

描述

bug

Environment

Unraid OS Version:
7.4.0 (API 4.37.11+8e587fe2)

Are you using a reverse proxy?
Yes (NPMPlus). I reproduced the issue directly on the server through the API's unix socket (/var/run/unraid-api.sock), without the proxy. The result is the same.

Pre-submission Checklist

  • I have verified that my Unraid OS is up to date
  • I have tested this issue by accessing my server directly (not through a reverse proxy)
  • This is not an Unraid Connect related issue (if it is, please submit via the support form instead)

Issue Description

The docker { logs } query returns an empty lines list and no error for a container that writes its log output to stderr. Containers that log to stdout return their lines as expected.

A client therefore cannot tell "the container logged nothing" from "the container logs to stderr", which is the default for Python's logging and many Go services.

Steps to Reproduce

  1. Start a container that only writes to stderr:

    docker run -d --name stderr-test alpine sh -c 'while true; do echo "to stderr" >&2; sleep 5; done'
    
  2. Check on the host that the output is on stderr only:

    # docker logs --tail 3 stderr-test
    to stderr
    to stderr
    to stderr
    # docker logs --tail 3 stderr-test 2>/dev/null
    #
    
  3. Look up the container id with query { docker { containers { id names } } } and request its logs, directly on the server:

    curl -s --unix-socket /var/run/unraid-api.sock http://localhost/graphql \
      -H "x-api-key: $KEY" -H "Content-Type: application/json" \
      -d '{"query":"{ docker { logs(id: \"<id>\", tail: 3) { lines { timestamp message } } } }"}'
    

Expected Behavior

The lines from both stdout and stderr, ordered by timestamp, as docker logs shows them.

Actual Behavior

{"data":{"docker":{"logs":{"lines":[]}}}}

No lines and no error. The same happens without tail and with since. On the same server, containers that log to stdout (for example jellyfin, pihole, redis) return lines through the same query.

Additional Context

DockerLogService.getContainerLogs in api/src/unraid-api/graph/resolvers/docker/docker-log.service.ts reads only stdout:

const { stdout } = await execa('docker', args);

docker logs writes the container's stderr stream to its own stderr, so that stream is dropped. The line is the same in v4.30.0, v4.35.0, v4.37.5, v4.37.11 and on main, so this is not a regression of 7.4.0.

Reading both streams would fix it, for example with execa's all: true and parsing all instead of stdout. --timestamps is already passed, so the lines can be put in order.

I searched open and closed issues and pull requests for an existing report and found none.

I first noticed this with a real container (unbound) and tracked it down with the help of an AI assistant. I ran the reproduction above myself on the server.

主要语言
TypeScript
星标
123
派生
25
平均合并
2 天 16 小时
30 天内合并 PR
9

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

unraid/api 的其他 Issue

查看 unraid/api 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。