7 printf "Cleaning up containers\n";
8 printf "----------------------\n";
9 my $psList = `docker ps -a`;
10 my @psItems = split /\n/, $psList;
12 # match 'docker ps' output to capture the container name
13 if($_ =~ /.*\s+([^\s]+)$/ig) {
14 my $containerName = $1;
15 if($containerName !~ /NAME/ig) {
16 printf "delete $containerName\n";
17 my $deleteOutput = `docker rm -f $1`;
18 print "$deleteOutput\n";
23 printf "Cleaning up volumes\n";
24 printf "-------------------\n";
25 my $volumeList = `docker volume ls`;
26 @volumeItems = split /\n/, $volumeList;
27 foreach(@volumeItems) {
28 # match 'docker volume ls' output to capture the volume name
29 if($_ =~ /([^\s]+)\s+([^\s]+)$/ig) {
31 if($volumeName !~ /NAME/ig) {
32 printf "delete $volumeName\n";
33 my $deleteVolumeOutput = `docker volume rm -f $volumeName`;
34 printf "$deleteVolumeOutput\n";
39 printf "Cleaning up images\n";
40 printf "------------------\n";
41 my $imageList = `docker images`;
42 @imageItems = split /\n/, $imageList;
43 foreach(@imageItems) {
44 # match 'docker images' output to capture the image id
45 if($_ =~ /([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+.*/ig) {
47 if($imageId !~ /IMAGE/ig) {
50 printf "delete $imageId ($imageRepo:$imageTag)\n";
51 my $deleteImageOutput = `docker rmi -f $imageId`;
52 printf "$deleteImageOutput\n";