Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter docker containers by name and stop them

Tags:

docker

I'm trying to stop all the containers starting with the name app_

I though this would work: docker stop $(docker ps -f name="app_*"), but it shows:

unknown shorthand flag: 'f' in -f
See 'docker stop --help'.

Is there a way to do this?

like image 811
prevox Avatar asked Oct 27 '25 10:10

prevox


1 Answers

You must put the complete filter expression into parantheses:

docker ps -f "name=app_*"

The search is fuzzy by default, so e.g. name=app will also return my-app. You can use a regex to indicate that the match should be at the start:

docker ps -f "name=^app_"

You should further add the quiet flag q so that the command only returns ids to make it work with docker stop:

docker stop $(docker ps -qf "name=^app_")
like image 76
code-gorilla Avatar answered Oct 29 '25 23:10

code-gorilla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!