On Ubuntu 14.04 (Trusty Tahr) I'm looking for a way to stop a running container and the only information I have is the image name that was used in the Docker run command.
Is there a command to find all the matching running containers that match that image name and stop them?
Following issue 8959, a good start would be:
docker ps -a -q --filter="name=<containerName>"
Since name
refers to the container and not the image name, you would need to use the more recent Docker 1.9 filter ancestor, mentioned in koekiebox's answer.
docker ps -a -q --filter ancestor=<image-name>
As commented below by kiril, to remove those containers:
stop
returns the containers as well.
So chaining stop
and rm
will do the job:
docker rm $(docker stop $(docker ps -a -q --filter ancestor=<image-name> --format="{{.ID}}"))