-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix(onboard): auto-cleanup orphaned gateway container on re-onboard #1615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+33
−3
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
In Docker CLI, fordocker ps --filter "name=...", what is the documented exact-match pattern behavior? Is^container-name$always reliable, or is^/container-name$(ordocker container inspect) recommended for exact name checks?💡 Result:
docker ps/docker container ls, thenamefilter “matches on all or part of a container’s name” (i.e., substring match). Docker’s CLI docs do not document an “exact match” mode forname=. [1]^...$) status: Docker’s general filtering docs say some filters support regex, but you must rely on each command’s own reference to know what’s supported—and thedocker psdocs for thenamefilter only describe substring matching, not regex/exact semantics. [2][1]⇒ So
--filter "name=^container-name$"is not documented as a reliable exact-match contract.^/name$: In the Engine API, container “Names” are represented with a leading slash (e.g.,"/coolName"). [4] This is why, in practice, exact-match regex attempts often use^/container-name$—but that’s still implementation-dependent, not the CLI’s documented promise. [4][1]docker inspect --type=container <name>(ordocker container inspect <name>).docker inspectis documented to match objects by ID or name (and--typeavoids ambiguity with non-container objects). [3]Bottom line: The documented
docker ps --filter name=...behavior is substring matching, not exact matching; for a dependable exact-name check, preferdocker (container) inspect <name>(optionally--type=container). [1][3]Sources: [1] Docker CLI
docker container ls(name filter) docs; [2] Docker “Filter commands” docs; [3] Docker CLIdocker inspectdocs; [4] Docker Engine API swagger (ContainerSummary.Namesexamples include leading/).Replace
docker pssubstring filter withdocker container inspectfor reliable exact-name matching (Line 1561).docker ps --filter "name=..."is documented as substring matching only; regex anchors like^...$are not part of the CLI's documented contract and can fail to detect containers. Usedocker container inspect <name>for deterministic exact-name/ID lookups.Suggested hardening
function cleanupOrphanedGatewayContainer() { const containerName = `openshell-cluster-${GATEWAY_NAME}`; - const existing = runCapture( - `docker ps -aq --filter "name=^${containerName}$"`, - { ignoreError: true }, - ).trim(); - if (!existing) return false; + const exists = run(`docker container inspect ${shellQuote(containerName)} >/dev/null 2>&1`, { + ignoreError: true, + }); + if (exists.status !== 0) return false; console.log(` Cleaning up orphaned gateway container (${containerName})...`); run(`docker stop ${shellQuote(containerName)} 2>/dev/null || true`, { ignoreError: true }); run(`docker rm ${shellQuote(containerName)} 2>/dev/null || true`, { ignoreError: true }); return true; }🤖 Prompt for AI Agents