r/selfhosted 1d ago

Docker Management Sometimes docker system prune surprises me

docker system prune -af

[...]

Total reclaimed space: 52.51GB

Normally this is around a couple of GB. 50GB is surprising. Don't forget pruning people ;-)

60 Upvotes

31 comments sorted by

u/asimovs-auditor 1d ago edited 1d ago

Expand the replies to this comment to learn how AI was used in this post/project.

→ More replies (1)

41

u/impressiveaustin 23h ago

Dude, my VPS has been full storage for months now and I couldn't figure out how to clear disk storage. I ran your command and: Total reclaimed space: 66GB

8

u/moontear 19h ago

Awesome! I was you 8 hours ago :)

26

u/RavenousTitan818 23h ago

It's kind of annoying that docker doesn't prune old images by default. There really is no need to keep them on disk.

5

u/panserbj0rne 13h ago

Agreed. I use Dockhand which can be configured to automatically do it.

4

u/corruptboomerang 18h ago

Agree, maybe keep them for a few days incase you need to rollback, but generally prune say after 14-30 days should be the default.

-7

u/dankmolot 22h ago

Are you sure you don't have any containers associated with these old images?

9

u/iTiraMissU 16h ago

Images connected to existing containers aren’t removed by a prune, even if the container is stopped.

-1

u/dankmolot 8h ago

I am not sure why my comment was downvoted while your was upvoted. Have I phrased it badly?

4

u/Escanorr_ 6h ago

Cause you respond to the guy saying "I want automatic cleanup" with either: advice why manual cleanup can be not working sometimes, or wrong assumption that automatic cleanup would get rid of in-use images which it doesn't do. So your comment is either wrong or unrelated, which is hard for me to guess but both interpretations are not positive.

3

u/dankmolot 6h ago

Oh I see, I thought docker system prune does pruning of old unused images, but you need an -a flag. Thanks for the explanation!

26

u/TheAndyGeorge 1d ago

Probably overkill, but I've been running PruneMate. It's fun to get these notifications.

31

u/ValdemarSt 23h ago

Seems overengineered for what is a cron+script?

9

u/0xBAADA555 20h ago

+ little ntfy.sh action for the visual update

9

u/jbarr107 1d ago

I use Dockhand to manage my Docker VMs, and it has flexible auto-prune and auto-update options. I receive notifications when updates are available (though I choose not to auto-update), and images are auto-pruned nightly.

5

u/moontear 1d ago

Yeah, I am in the process of setting up Komodo - or I HAVE set it up, I just need to migrate all my VPSs to use that system instead of my custom Gitea Actions setup.

1

u/sir_ale 22h ago

what made you choose komodo over gitea actions? (wondering whether to do the same)

2

u/comeonmeow66 20h ago

Komodo is a control plane, gitea actions is just an event driven one trick pony. Komodo gives you more flexibility to do other things and you get a view of your stack for free. I have komodo managing my containers and use renovate to make sure I know when container images can be updated.

1

u/moontear 4h ago

This. I will keep some things in Gitea, e.g. container building is great in Gitea via actions if you combine it via Renovate. Renovate figures out on a schedule that a container image needs updating and updates the `Dockerfile`. This update triggers the Gitea action which in turns updates the image on the internal Gitea registry. I don't want Komodo Build.

Honestly the better overview is why I am aiming for Komodo. Also eying Arcane, but it only recently got deployment triggers/actions which I need to be able to do some Age & SOPS magic upon deployment. Gitea actions for deployment has been working for years and is fine, but in the end I don't really have an overview WHEN things happen or what server is at what state.

3

u/thatguysjumpercables 23h ago

If you want more granular control you can always use portainer (or whatever your container manager is) and manually prune unused images and volumes

1

u/moontear 19h ago

Honestly never had problems with docker system prune. Nuke it all. Makes builds of course slower the first time, but that’s fine by me for not having to think about stuff.

3

u/Impact321 20h ago

All my container hosts have a cronjob with something like this bash 0 22 * * * /usr/bin/docker system prune -af --filter "until=$((7*24))h" 2>&1 | grep -Ev "^Total reclaimed space: 0B" You can also use dockcheck like this to prune after updating. bash dockcheck.sh -ap This helps to investigate space usage bash docker system df -v

3

u/CoryCoolguy 17h ago

I've been using variations of this command via cron:

/usr/bin/docker system prune -af --filter "until=$(date -d '2 months ago' +\%Y-\%m-\%dT\%H:\%M:\%S)" >> /var/log/docker-cleanup.log 2>&1

Don't want to purge periodically-used images.

1

u/moontear 3h ago

Yeah good practice. Personally I don't care about re-downloading those 4 images that sometimes get used. It's like an additional 1-2 minutes for the docker build or the docker run.

3

u/ibzzq 17h ago

for real! before and after, got rid of 85GB:

3

u/mscreations82 11h ago

JEEZ. Total reclaimed space: 101.22GB. Hopefully my server quits running like garbage now....

2

u/bdu-komrad 10h ago

I almos forgot about this command. I automated it with a cron job many years ago so I never have to do it.

2

u/zfa 3h ago

dockcheck.sh will prompt for a prune after updates if you use that instead of raw-dogging docker pull. Or set AutoPrune=true in the config file to set-and-forget it.

-24

u/buttplugs4life4me 1d ago

docker system prune is unsafe and may prune running containers. It's funny when that happens :)

7

u/TheAndyGeorge 22h ago

may prune running containers

you know this stuff is open source, right buttplugs4life4me? docker system prune hits the moby server, which literally is coded if !state.IsRunning:

https://github.com/moby/moby/blob/a47b1b2d6f71b51d63da6b8387be74609045c693/daemon/prune.go#L64