How can I check how many containers are running a certain docker image?

The accepted answer didnt work for me nor did https://stackoverflow.com/users/2915097/user2915097

So I kinda tweaked it;

 docker ps -q | wc -l

All the answers basically try to get the list and do a line count.


Can you use something like

docker inspect --format='{{.Container.Spec.Image}}' $(docker ps -q) and test the image returned by this command?

UPDATE: How about combining this with the accepted answer (as of Mar-2022)? Into something like this: docker inspect --format='{{.Config.Image}}' $(docker ps -q) | grep imagename | wc -l


How about

docker ps | grep imagename | wc -l