Docker Community Forums

Share and learn in the Docker community.

Unable to stop docker containers meeting certain regex patterns

docker

(Bluemind2005) #1

Hey Guys,

I have few containers like below:

44e31276a61d        centos              "/bin/bash -c 'while…"   53 seconds ago      Up 52 seconds                           dazzling_hopper
c93af9e36e5f        centos              "/bin/bash -c 'while…"   54 seconds ago      Up 53 seconds                           hopeful_tereshkova
fcfb56bd7b93        centos              "/bin/bash -c 'while…"   54 seconds ago      Up 53 seconds                           condescending_mahavira
a4b7a6d0f0df        centos              "/bin/bash -c 'while…"   55 seconds ago      Up 53 seconds                           loving_archimedes
09b0f7e8102c        centos              "/bin/bash -c 'while…"   55 seconds ago      Up 54 seconds                           wonderful_ardinghelli
a74098dfd87a        centos              "/bin/bash -c 'while…"   55 seconds ago      Up 54 seconds                           stupefied_edison
5c8ca05a5461        centos              "/bin/bash -c 'while…"   56 seconds ago      Up 55 seconds                           hopeful_wing
1c0ab6ea8c56        centos              "/bin/bash -c 'while…"   56 seconds ago      Up 55 seconds                           dreamy_jang
bee9df761a47        centos              "/bin/bash -c 'while…"   57 seconds ago      Up 55 seconds                           priceless_hoover
f77d270c97c9        centos              "/bin/bash -c 'while…"   57 seconds ago      Up 56 seconds                           goofy_bhabha
1acdc11c65c5        centos              "/bin/bash -c 'while…"   57 seconds ago      Up 56 seconds                           quizzical_gates
48afc7496be4        centos              "/bin/bash -c 'while…"   58 seconds ago      Up 57 seconds                           hungry_curran

I basically want to stop all containers starting with 4*. Unfortunately docker stop doesn’t have the capability to stop the docker containers matching certain regular expression like 4? or 4*

Any idea how do I go about it ?

Thanks


(Bluemind2005) #2

Unfortunately, no provision to filter with id meeting a regex pattern !


(Bluemind2005) #3

Not an elegant solution but this is how I did :

docker ps -aqn 10|xargs docker stop|xargs docker rm

If anyone knows any better or elegant approach, Happy to learn !

Thanks