Skip to content

cli/command/formatter: restore fallback for container names with slashes - #7481

Merged
thaJeztah merged 1 commit into
docker:masterfrom
dperny:fix-container-names-fallback
Nov 5, 2026
Merged

thaJeztah merged 1 commit into
docker:masterfrom
dperny:fix-container-names-fallback

Conversation

@dperny

@dperny dperny commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Since v29.4.0, docker ps prints an empty NAMES column, and {{.Names}}
is empty, when every name of a container contains a slash after the leading
/ is stripped.

That is the case with a classic Swarm API. Classic Swarm prefixes container
names with the node name, so they come back as /<node-name>/<container-name>.
Although classic Swarm is archived upstream, we still maintain a fork of it.

#6875 optimized ContainerContext.Names. When truncating, it returns the first
name without a slash and skips legacy --link aliases. But when no such name
exists, it now returns an empty string. Before #6875, all names were printed in
that case, the same as with --no-trunc.

This patch restores that fallback. The common case, where the first name has no
slash, is unchanged: it still returns on the first iteration without allocating.

Added test cases for:

  • A truncated name with a node prefix (/node-1/foobar_baz → node-1/foobar_baz).
    This one fails without this patch.
  • A truncated list where a link alias comes before the container's own name.
  • A non-truncated list that includes a link alias.

Release notes (optional)

Fix `docker ps` printing an empty `NAMES` column when all of a container's names contain a slash, such as when connected to a classic Swarm API.

🤖 Generated with Claude Code

Since commit f7a909d, ContainerContext.Names returns an empty string
when truncating and every name of the container contains a slash. Before
that change, all names were printed in that case.

Classic Swarm prefixes container names with the node-name
("/<node-name>/<container-name>"), so `docker ps` against a classic Swarm
API printed an empty NAMES column.

Restore the fallback to printing all names when no name without slashes
is found.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Drew Erny <derny@mirantis.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@thaJeztah
thaJeztah merged commit 2b3688f into docker:master Nov 5, 2026
114 of 119 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants