Short Script to remove all stopped/exited docker containers

  1. Create a file: remdockerinstances.sh on your docker host machine
  2. Copy the below content in remdockerinstances.sh
  3. #!/bin/bash
    rm instanceinfo.txt
    sudo docker ps -a | awk ‘{print $1}’ > instanceinfo.txt
    echo “$(tail -n +2 instanceinfo.txt)” > instanceinfo.txt
    while read line; do
    sudo docker rm “${line}”
    done < instanceinfo.txt
  4. Save the file and run ./remdockerinstances.sh instanceinfo.txt
  5. Enjoy 🙂
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s