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?
In my case
--filter ancestor=<image-name>
was not working, so the following command cleaned up the Docker container for me:Following issue 8959, a good start would be:
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.As commented below by kiril, to remove those containers:
So chaining
stop
andrm
will do the job:I was trying to wrap my Docker commands in gulp tasks and realised that you can do the following:
This might not work for scenarios where you have multiple containers with the same name (if that's possible), but for my use case it was perfect.
For Docker version 18.09.0 I found that format flag won't be needed