Skip to content

fix: detect container ID when /var/lib/docker is a separate mount#747

Merged
buchdag merged 1 commit into
nginx-proxy:mainfrom
JamBalaya56562:fix/452-container-id-mountinfo
Jun 28, 2026
Merged

fix: detect container ID when /var/lib/docker is a separate mount#747
buchdag merged 1 commit into
nginx-proxy:mainfrom
JamBalaya56562:fix/452-container-id-mountinfo

Conversation

@JamBalaya56562

Copy link
Copy Markdown
Contributor

GetCurrentContainerID reads /proc/<pid>/mountinfo and, on a mountinfo line, anchored the container-id match to a literal containers/ path segment. When /var/lib/docker/containers (or /var/lib/docker) is its own mount, the per-container files appear as /<id>/hosts with no containers/ segment, so detection returned empty and .Docker.CurrentContainerID was blank — breaking templates that rely on it (e.g. nginx-proxy, causing 502s).

This anchors the id to a known per-container file instead (/<id>/(hostname|hosts|resolv.conf)), matching both the default layout (/var/lib/docker/containers/<id>/hosts) and a separate-mount layout (/<id>/hosts), while still excluding the overlay2 layer hashes in the mount options. The cpuset/cgroup paths are unaffected.

Adds TestGetCurrentContainerIDSeparateMount; the existing #355 mountinfo test still passes.

Fixes #452

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes .Docker.CurrentContainerID detection when /var/lib/docker (or /var/lib/docker/containers) is mounted separately, causing mountinfo paths to appear as /<id>/hosts without a containers/ segment and previously resulting in an empty container ID.

Changes:

  • Updates mountinfo parsing to anchor the container ID match to known per-container files (hostname, hosts, resolv.conf) instead of requiring a literal containers/ path segment.
  • Adds a regression test covering the “separate mount” mountinfo layout from issue #452.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/context/context.go Adjusts mountinfo-specific regex to match container IDs via /<id>/(hostname|hosts|resolv.conf) so separate-mount layouts are detected.
internal/context/context_test.go Adds TestGetCurrentContainerIDSeparateMount to validate detection when per-container files appear under /<id>/... paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@buchdag buchdag force-pushed the fix/452-container-id-mountinfo branch from 94e0be1 to 1b86f10 Compare June 28, 2026 12:01
@buchdag buchdag merged commit c32a5c3 into nginx-proxy:main Jun 28, 2026
6 checks passed
@buchdag buchdag changed the title Detect container ID when /var/lib/docker is a separate mount fix: detect container ID when /var/lib/docker is a separate mount Jun 28, 2026
@JamBalaya56562 JamBalaya56562 deleted the fix/452-container-id-mountinfo branch June 28, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CurrentContainerID is blank when /var/lib/docker/containers is a separate mount point on the host

3 participants