DEV Community

Alexey Melezhik
Alexey Melezhik

Posted on

Remove dangling docker images and stopped containers. Cross platform solution.

I know there are a lot of solutions for this, however if you need cross platform solution working both for for Windows and Linux OS, just use small and nifty sparrow plugin docker-remove-dangling-images:

$ sparrow plg install docker-remove-dangling-images
$ sparrow plg run docker-remove-dangling-images
Enter fullscreen mode Exit fullscreen mode

Best

Alexey

Top comments (8)

Collapse
 
pkristiancz profile image
Patrik Kristian

why just do not create function for that? or even alias

Collapse
 
melezhik profile image
Alexey Melezhik • Edited

A few points:

  • how about windows?
  • if you move to another machine you will need to deploy all the bash functions, aliases again ... and when you create scripts this way you tend to do it woking in my machine, hard to port, deliver and maintain ...

I know there is dot files and GH, but this only works well for very "simple/one time purposes" scripts, reality is eventually any script gets more complicated and needs proper distribution mechanism.

Collapse
 
pkristiancz profile image
Patrik Kristian

On windows i personally use git-bash
as i looked (hopefully on right source) everything is oneliner, so i do not see point of installing something, what is as long as command itself

Thread Thread
 
pkristiancz profile image
Patrik Kristian

end actually, i think most people would need to install sparrow. (never heard of it)
imho overkill

Thread Thread
 
melezhik profile image
Alexey Melezhik • Edited
  1. I don't want to install git bash for the sake of running simple script.

  2. My point is that everything that starts as one liner command eventually might turn in more complicated script.

Well, you are fine as long as you create something that is working only for you and your environment.

While idea behind the Sparrow is portable scripts for community which get installed and run without any fuss.

The real benefit of using Sparrow is that you develop script with distribution and maintenance in mind rather then creating one time solutions which only works for you.

Thread Thread
 
pkristiancz profile image
Patrik Kristian

maybe i will check out sparrow someday, doesnt sound bad...

ad 1. if you use git (which you should), you have git-bash already installed

Collapse
 
beerus profile image
Piccolo • Edited

Why not just use the official way:

docker container prune -f
docker image prune -f
Enter fullscreen mode Exit fullscreen mode
Collapse
 
melezhik profile image
Alexey Melezhik • Edited

Hi @Paulius, thanks for suggestion, fixed at version 0.0.8:

$ sparrow plg run docker-remove-dangling-images --nocolor
sparrow root: [C:\Users\melezhik/sparrow]
Total reclaimed space: 0B
Deleted Images:
deleted: sha256:579734eacb77553190fb716ba4c9820eac568316912336c9f8e0d62149790ca9
deleted: sha256:b5bb98175c85070b93b0b495babbbae30b783b72c913f22b13f4365557bdac40

Total reclaimed space: 634.4MB
STATUS  SUCCEED