'Run docker commands using glob / wildcard on container names
I'm using docker-compose up --scale to create multiple versions of the same container. As a result I end up with containers named container_foo_1, container_foo_2 etc.
Does docker support any kind of glob / wildcard matching on container names in it's command line tools? What I want to do is this:
docker inspect container_foo_*
What I'm doing right now in the short term is just using:
docker-inspect container_foo_{1,2} (using bash brace expansion)
but I'd love if there was a way where I didn't know how many containers there were / what the numbers were ahead of time.
Solution 1:[1]
You can use the argument --filter | -f at docker ps with docker inspect.
Usage: docker ps --filter key=value,
where value accept regular expressions.
The currently supported filters are:
idContainer’s IDnameContainer’s namelabelAn arbitrary string representing either a key or a key-value pair. Expressed as or =exitedAn integer representing the container’s exit code. Only useful with --all.statusOne of created, restarting, running, removing, paused, exited, or deadancestorFilters containers which share a given image as an ancestor. Expressed as * [:], , or image@digestbefore or sinceFilters containers created before or after a given container ID or namevolumeFilters running containers which have mounted a given volume or bind mount.networkFilters running containers connected to a given network.publish or exposeFilters containers which publish or expose a given port. Expressed as<port>[/<proto>]or<startport-endport>/[<proto>]healthFilters containers based on their healthcheck status. One of starting, healthy, unhealthy or none.isolationWindows daemon only. One of default, process, or hyperv.is-taskFilters containers that are a “task” for a service. Boolean option (true or false)
Ex: docker inspect $(docker ps --filter name=^/server --quiet)
References:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mehyaa |
