Saturday, April 4, 2015

Docker - Remove All Containers by Image Name or ID

As I monkey around with Docker, I find that it is sometimes useful to remove all the containers based on the same image in a single command. So , without further ado, create a file in your PATH named docker-rmall and paste the following code into it: #!/bin/bash
docker rm $(docker ps -a | grep $1 | awk '{ print $1 }' | grep -v CONTAINER)
Make sure you grant executable permissions on the file. Now, to remove all of the containers associated with a particular image, you can simply run: docker-rmall <some_image_name_or_id>

No comments:

Post a Comment