Remove All Docker Containers for a Specific Image on Linux
Optimize Docker Performance: Stop and Remove All Containers Running a Specific Image.
This is to stop and remove all docker containers running a specific image (or other common name) on Linux.
docker ps -a | awk '{ print $1,$2 }' | grep moby/buildkit:buildx-stable-1 | awk '{print $1 }' | xargs -I {} docker stop {} | xargs -I {} docker rm {}
In this case, I needed to cleanup all containers running image moby/buildkit:buildx-stable-1 due to a Gitlab runner failing to perform cleanups after running build jobs.