Clean up docker containers

Docker is an excellent tool, some times I forget or don’t bother to delete old containers or images. After using docker on a project for a while I often find I have 100s of old unneeded containers and image that need to be deleted. Here is an easy way to delete all containers and images, I hope you find it useful,

Put these in a bash script, mark the bash script as executable.

#!/bin/bash 
docker stop $(docker ps -a -q)
docker rm `docker ps -notrunc -a -q`
docker rmi $(docker images -a -q)

 

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