'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:
id
Container’s IDname
Container’s namelabel
An arbitrary string representing either a key or a key-value pair. Expressed as or =exited
An integer representing the container’s exit code. Only useful with --all.status
One of created, restarting, running, removing, paused, exited, or deadancestor
Filters containers which share a given image as an ancestor. Expressed as * [:], , or image@digestbefore or since
Filters containers created before or after a given container ID or namevolume
Filters running containers which have mounted a given volume or bind mount.network
Filters running containers connected to a given network.publish or expose
Filters containers which publish or expose a given port. Expressed as<port>[/<proto>]
or<startport-endport>/[<proto>]
health
Filters containers based on their healthcheck status. One of starting, healthy, unhealthy or none.isolation
Windows daemon only. One of default, process, or hyperv.is-task
Filters 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 |