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 comma
Stop docker container by image name:
imagename='mydockerimage'
docker stop $(docker ps | awk '{split($2,image,":"); print $1, image[1]}' | awk -v image=$imagename '$2 == image {print $1}')
Stop docker container by image name and tag:
imagename='mydockerimage:latest'
docker stop $(docker ps | awk -v image=$imagename '$2 == image {print $1}')
If you created the image, you can add a label to it and filter running containers by label
docker ps -q --filter "label=image=$image"
Unreliable methods
docker ps -a -q --filter ancestor=
does not always work
docker ps -a -q --filter="name="
filters by container name, not image name
docker ps | grep | awk '{print $1}'
is problematic since the image name may appear in other columns for other images