Skip to content

feat(docker): add bounded tail reads for log files inside containers #5703

Open

Description

@HaroldXd

What problem will this feature address?

Applications can write logs to files inside containers without forwarding them to stdout/stderr. For example, Laravel commonly writes to /var/www/html/storage/logs/laravel.log.

The existing docker.readContainerFile endpoint returns only the beginning of a file, capped at 512 KiB, with a truncated flag. It provides no way to request the end of the file. As a result, API and MCP clients may receive old errors while recent entries remain inaccessible through this endpoint.

We encountered this while investigating a Laravel application: container logs showed HTTP access output, while reading laravel.log returned a truncated prefix containing historical exceptions.

This behavior is visible in readContainerFile on canary at e0c8d80: the command uses cat … | head -c ….

Reproduction:

  1. Create a text log larger than 512 KiB inside a running container.
  2. Append a unique marker such as LATEST_ERROR_MARKER.
  3. Call docker.readContainerFile for that path.
  4. Observe truncated: true; the latest marker is absent.
  5. The endpoint has no tail or offset parameter to retrieve it.

Describe the solution you'd like

Add a read-only docker.readContainerFileTail endpoint, keeping existing file-editor behavior unchanged.

Suggested input:

{
  "containerId": "<container-id>",
  "path": "/var/www/html/storage/logs/laravel.log",
  "lines": 200,
  "maxBytes": 65536
}

Support the existing optional serverId for remote servers. Defaults and upper limits are open to maintainer feedback.

Expected behavior:

  • Return the most recent requested lines in their original chronological order.
  • Enforce a server-side byte limit, including for extremely long lines.
  • When the byte limit is reached, retain the newest content and indicate truncation.
  • Return UTF-8 text with explicit truncation metadata.
  • Bound memory usage and execution time.
  • Preserve authorization and organization/server access checks.
  • Validate paths and numeric limits; do not accept arbitrary shell commands.
  • Report missing files, unavailable containers, and unsupported container utilities clearly.

Initial scope: a single snapshot read. Live following, search, pagination, and dashboard changes can be separate contributions.

Suggested tests include large files with a marker at EOF, empty files, missing trailing newlines, Unicode boundaries, oversized lines, unusual filenames, failed reads, authorization, and local/remote execution.

Describe alternatives you've considered

  • Forward application logs to stderr: useful where configurable, but requires changing each application's logging setup.
  • Use SSH or the container terminal: works interactively, but does not provide a bounded, structured API for clients.
  • Download the complete file: unnecessary transfer for inspecting recent errors.
  • Increase the existing preview limit: still returns the beginning and does not solve the underlying limitation.

Additional context

Related work reviewed:

These address adjacent functionality. I did not find an equivalent container-file tail endpoint in the PR searches.

The proposed endpoint would also benefit the official MCP once included in its generated tool definitions.

Will you send a PR to implement it?

Yes, after alignment on the API and scope.

Activity

  1. linear-code commented on Oct 18, 2026

    @linear-code
  2. VijinV commented on Oct 26, 2026

    @VijinV

    I checked the current #5704 implementation. It remains open and unmerged. Its missing import and split-UTF-8 handling have been updated, but tailing lines before applying the byte window can still transfer a very large line out of the container, and there is no read deadline.

    I opened draft #5785 as a separate alternative for maintainer comparison: it applies the byte window inside the container first, then selects the newest lines, uses argument-array Docker exec without a shell pipeline, validates regular-file metadata, bounds output and caller time, preserves authorization, and reports line/byte truncation separately.

    Validation: 63 tests pass under Node 24.22.1, including 8 real Linux Docker tests. The PR describes the API and remaining Docker-exec cancellation limitation. Existing editor behavior is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions