Stopping Docker containers by image name - Ubuntu


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?

This question is tagged with docker ubuntu docker-image

~ Asked on 2015-08-18 13:35:17

The Best Answer is


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}}"))

~ Answered on 2015-08-18 13:40:17


The previous answers did not work for me, but this did:

docker stop $(docker ps -q --filter ancestor=<image-name> )

~ Answered on 2016-01-20 12:05:43

Most Viewed Questions: