Skip to content

feat: expose current container to templates#758

Open
JamBalaya56562 wants to merge 1 commit into
nginx-proxy:mainfrom
JamBalaya56562:feat/458-current-container
Open

feat: expose current container to templates#758
JamBalaya56562 wants to merge 1 commit into
nginx-proxy:mainfrom
JamBalaya56562:feat/458-current-container

Conversation

@JamBalaya56562

@JamBalaya56562 JamBalaya56562 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Problem

When docker-gen runs standalone (not bundled with nginx-proxy) with -only-exposed / -only-published, the docker-gen container itself exposes no ports and is dropped by the server-side container filter. Templates that resolve the current container via where $ "ID" .Docker.CurrentContainerID | first then get nil, even though .Docker.CurrentContainerID is detected correctly.

Change

  • Adds a CurrentContainer() method on the root Context, returning the *RuntimeContainer whose ID matches .Docker.CurrentContainerID (or nil), so templates can write {{ with .CurrentContainer }}…{{ end }}.
  • In getContainers, after the filtered list is built, the current container is inspected and appended when its ID is non-empty and not already present — so it is available even when -only-exposed/-only-published would otherwise filter it out.

Implementation notes

  • The per-container inspect→RuntimeContainer conversion is extracted into an inspectContainer helper so the same logic serves both the list loop and the always-include path, without duplication.
  • The current-container lookup goes through a small package-level indirection (getCurrentContainerID) so the append path can be unit-tested without a live /proc.

Tests

  • TestCurrentContainer covers the match / no-match / empty-ID cases of the accessor.
  • TestGetContainersIncludesCurrentContainer verifies the container is appended when it is absent from the filtered list.
  • README documents .CurrentContainer.

Fixes #458

@JamBalaya56562 JamBalaya56562 force-pushed the feat/458-current-container branch from 58953bd to 16eb7dd Compare July 11, 2026 20:02
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.

$CurrentContainer cannot be initialized when -only-exposed is used

1 participant