Removing all Docker containers with one shell command

Written by Johannes on July 26, 2014 Categories: bash-Scripts, docker

Your ads will be inserted here by

Easy AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

After fiddling around with docker a bit I wanted to delete all the containers I had accumulated during the tutorial. Maybe there is a quicker way to do it, but it also worked with awk.

sudo docker ps -a | \  # list all containers running and stopped
  awk 'BEGIN { FS=" [ ]+" }; { print $6 }' | \ # use at least two spaces as separator
  awk '{ if (NR!=1) {print}}' | \ # strip first line
  xargs sudo docker rm  # apply docker removal command

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre user="" computer="" escaped="">