Monday, April 3, 2017

Docker Purge

There comes a time, when you just want to purge all the docker things from a machine. Over time, you can accumulate a bunch of garbage, and not even really realize it. While playing around at work and at home, I came up with this little script I use pretty often to clear out my working Docker environment on a system.

#!/bin/sh
containers=$(docker ps -a -q)
if [ ! -z "$containers" -a "$containers" != " " ]; then
  echo Stopping $containers
  docker stop $containers
  docker rm $containers
else
  echo No containers running
fi

images=$(docker images -a -q)
if [ ! -z "$images" -a "$images" != " " ]; then
  echo Removing Images $images
  docker rmi $images
else
  echo No images installed
fi

docker volume prune -f
docker network prune -f

This can be used on Linux, Bash for Windows, and even CGWyn. Basically, stop all containers, remove them, remove all images, prune all volumes, and prune all networks.

If you have any improvements to this, let me know down below in the comments!

11 comments:

for ict 99 said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.

Unknown said...

I read your Blog Your explanation is really good just check it once once Devops Online Training Hyderabad to Know more.

Chandu Chinnu said...

GREAT topic! It is really interesting to read from the beginning & I would like to share your blog to my circles, keep sharing… DevOps Online Training
DevOps Training
DevOps Online Training

Family Matters in Islam said...

I loved your Blog forThe Earth Day Quizzes For Planting trees, I'm going to Follow Your Post for my Gardening and planting trees on Earth day. You are an amazing nature loving Person.

jenifer irene said...

Very interesting post! Thanks for sharing your experience suggestions.
Aviation Academy in Chennai
Air hostess training in Chennai
Airport management courses in Chennai
Ground staff training in Chennai
Aviation Courses in Chennai
air hostess academy in Chennai
Airport Management Training in Chennai
airport ground staff training in Chennai

iven said...

You are a very persuasive writer. I can see this in your article. Nice Post. You have a way of writing compelling information that sparks much interest.

iven said...

This is a informative post. Post that is trustworthy, informative, and local will be, The good news is that once you stop posting such clickbait stories. My social platforms are given below. Please follow us.
ted
angel
seekingalpha

Edward Snowden said...

Great post, thanks for giving us nice info.Fantastic Good Post
walk-through. I appreciate this post.

Anu said...


Excellant post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it. DevOps Training in Chennai | DevOps Training in anna nagar | DevOps Training in omr | DevOps Training in porur | DevOps Training in tambaram | DevOps Training in velachery

keerthana said...

Really it is very useful for us.....This information seems to be more unique and interesting.
Thanks for sharing. PHP Training in Chennai | Certification | Online Training Course | Machine Learning Training in Chennai | Certification | Online Training Course | iOT Training in Chennai | Certification | Online Training Course | Blockchain Training in Chennai | Certification | Online Training Course | Open Stack Training in Chennai |
Certification | Online Training Course


IT said...

The effectiveness of IEEE Project Domains depends very much on the situation in which they are applied. In order to further improve IEEE Final Year Project Domains practices we need to explicitly describe and utilise our knowledge about software domains of software engineering Final Year Project Domains for CSE technologies. This paper suggests a modelling formalism for supporting systematic reuse of software engineering technologies during planning of software projects and improvement programmes in Final Year Projects for CSE.

Software management seeks for decision support to identify technologies like JavaScript that meet best the goals and characteristics of a software project or improvement programme. JavaScript Training in Chennai Accessible experiences and repositories that effectively guide that technology selection are still lacking.

Aim of technology domain analysis is to describe the class of context situations (e.g., kinds of JavaScript software projects) in which a software engineering technology JavaScript Training in Chennai can be applied successfully

The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training