Reputation: 10604
During development i often come to the point where I need to delete a docker image, but also to first stop and remove all containers using it. So essentially I am doing:
Any shortcut for this?
Upvotes: 1
Views: 315
Reputation: 4907
You can use simple bash script for this
#!/bin/bash
docker stop $(docker ps --filter ancestor=$1 --format="{{.ID}}")
docker rm $(docker ps -a --filter ancestor=$1 --format="{{.ID}}")
docker rmi $1
Just call it:
./remove-img.sh <image-name>
Upvotes: 4