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

オープン 初心者向け
#2,150 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
9

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

unraid/api のほかの issue

unraid/api の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。