Automatically remove 'unused' images from Portainer

  • Hi, guys!
    Is it possible to automatically remove 'unused' images from Portainer?
    Previously I used OMV4 and there was very easy way for clean up 'old' images, just one command in scheduler if I`m not mistaken. But in OMV5 I don`t see any options except manual.


    I have container with watchtower which update my dockers when they have new version and very often I can see these pictures, sometimes I don`t have time for checking them every day and by the end of the week I can get till 5Gb storage space which was taken by unused images.



    omv5.pngomv5_2.png

    NAS: OMV 5
    (Intel i5 4570❄Gigabyte GA-H97N-WIFI❄8GB DDR3❄SSD EVO850➕WD Red 3TB➕WD Red 6TB➕WD Gold 8TB)
    Gigabit Internet➕Mikrotik hAP ac²

  • You can still use a scheduled job to do this.


    I run this daily at midnight:


    Code
    docker images -q --filter "dangling=true" | xargs -n1 -r docker rmi


    Try it in the shell first to see that it works.

    --
    Google is your friend and Bob's your uncle!


    OMV AMD64 5.x on ASRock Rack C2550D4I C0 Stepping - 16GB ECC - Silverstone DS380 + Silverstone DS380 DAS Box.

  • Thanks a lot! It helped, but this command removed even more than I expected :D
    Didn`t get what does this command do - " xargs -n1 -r docker rmi"


    I had only 1 'unused' image for today, but after run it from terminal I see even 4 removed items:

    Bash
    root@Server:~# docker images -q --filter "dangling=true" | xargs -n1 -r docker rmi
    Untagged: plexinc/pms-docker@sha256:e44b21dad945da8c8559352be0dbf829076798d0a4c84a5b2be15e0c29defe0e
    Deleted: sha256:f7e500371bed7cfa1627d892571eddd2c77c83c0edca2f53a41c4ec893a56887
    Deleted: sha256:8846b65447b959e3315caf6fd377735f2f452370649511483b2a3218ffc8cebd
    Deleted: sha256:658d69541077d587f13a911e23eced3d5591d1905758c42998bdc877e960284d
    Deleted: sha256:05fcfe2cdfa83bfe4bb1a3df91cccc26b66f6c6c0b3d5ab3d70d2d32cbc2d565

    I hope that`s fine, because nothing broken. And for future I`m going to create usual job
    Screenshot_1.png
    Probably, also could be used next command:


    Found here http://queirozf.com/entries/do…aning-up-unused-resources

    Bash
    docker rmi $(docker images --quiet --filter "dangling=true")

    NAS: OMV 5
    (Intel i5 4570❄Gigabyte GA-H97N-WIFI❄8GB DDR3❄SSD EVO850➕WD Red 3TB➕WD Red 6TB➕WD Gold 8TB)
    Gigabit Internet➕Mikrotik hAP ac²

  • Don't worry about what you saw, I see similar all the time. From today's run here:


    Untagged: linuxserver/jackett@sha256:bc673819ddade6716b7f46241d27ba69895d94eee5d8ecae1d61adb188a363e5Deleted: sha256:0b7c5d34ea96b577f271d33c10b2812f5dbeddba19ffc65cb62805d69983c8a5Deleted: sha256:08014f12fb51399a9fb221e336a0e74e9f91e80dd56a8f6e974b32c604bb9802Deleted: sha256:71cd0bbea496c9416c10f7d5d8b1d20e7366664a98e22b60bf3f169627441537

    --
    Google is your friend and Bob's your uncle!


    OMV AMD64 5.x on ASRock Rack C2550D4I C0 Stepping - 16GB ECC - Silverstone DS380 + Silverstone DS380 DAS Box.

  • BTW: decided to add one more command in scheduler for clean up unused volumes, found that I have one unused, already checked it, works:

    Bash
    docker volume rm $(docker volume ls -f dangling=true -q)

    NAS: OMV 5
    (Intel i5 4570❄Gigabyte GA-H97N-WIFI❄8GB DDR3❄SSD EVO850➕WD Red 3TB➕WD Red 6TB➕WD Gold 8TB)
    Gigabit Internet➕Mikrotik hAP ac²

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!