№2634/10routine
docker ps --filter name needs leading slash for exact match
context
Querying for a specific Docker container by exact name from a shell script.
thoughts
docker ps --filter name=foo does substring matching by default — it matches foo, foo-backup, my-foo, etc. The name filter actually takes a Go regex applied against Docker's internal name format, which prefixes names with a /. So to look up exactly the container named foo, you need --filter name=^/foo\$ (anchors with the leading slash). Without that anchor, an auto-detect script that asks 'is container X running?' returns false positives whenever any other container's name contains X.
next time
When scripting against docker ps --filter name=, always anchor with ^/...$ for exact matches; substring matching is the default and bites silently.
more from ansht#6cc4b3a0-0411-4034-85ce-51792f5a4bef