12

I have watchtower to keep my 50 production docker containers up to date. So far I have never had to resort to an old image since the new one was bugged but I know of the risks and dont have the --cleanup flag activated so I could easily spin up the old image if necessary. I also keep daily (mirrored) backups so I should be ok in the case of failure.

But I keep running into space issues due to multiple GBs of old images that I have to manually remove to not fill up the rather small ssd.

Does anyone have an idea how to automatically remove all but the newest unused docker image so I can quickly revert to it in case of failure but once there is another unused one of this container it goes away?

It's probably no big deal but searching for it together with watchtower didnt yield anything so far.

Thanks in advance and have a good one.

top 11 comments
sorted by: hot top controversial new old
[-] Nouveau_Burnswick@lemmy.world 6 points 9 months ago

Not to my knowledge, but you can set up a cron job to prune containers older than X days.

[-] haui_lemmy@lemmy.giftedmc.com 3 points 9 months ago

Yeah, I found the docker system prune filter option in the docs as well. Very unprecise sadly but thanks for mentioning it. :) I'm thinking of something like "when updating, first copy the version number of the old image and exclude it from prune". Probably going to have to write something myself again. Feel free to spitball with me.

[-] Nouveau_Burnswick@lemmy.world 1 points 9 months ago

So my thought with the time based pruning is that you can keep a backup that's X days old.

Let's say you keep 2 weeks. If there have been no problems with an image after 2 weeks of an update, you're probably good to go. If you have an issue during those 2 weeks, you can return to and image within those 2 weeks. If you've had no problems after 2 weeks, it's probably stable.

Adjust 2 weeks to whatever you're comfortable with.

[-] haui_lemmy@lemmy.giftedmc.com 1 points 9 months ago

This would absolutely make sense, were it not for the fact that the old image can be 3 weeks old when the new one comes out. Feel free to correct me but I think a time based option on age is not sufficient.

[-] Nouveau_Burnswick@lemmy.world 2 points 9 months ago

Correct, that would not work for that case.

[-] haui_lemmy@lemmy.giftedmc.com 1 points 9 months ago

But thanks for suggesting and spitballing with me.

[-] phrogpilot73@lemmy.world 5 points 9 months ago

Not to sound flippant, but it seems like a solution looking for a problem. I use the --cleanup flag, and if there's an issue, rolling back is as simple as changing dockerimage:latest to dockerimage:version that worked.

Unless I'm missing something.

[-] ShortN0te@lemmy.ml 1 points 8 months ago

I agree. If OP is scared that the image creator is clearing the old images, then OP should just mirror the registry or just have a system backup.

[-] ssdfsdf3488sd@lemmy.world 1 points 8 months ago

Pretty much this. I don't even bother with watchtower anymore. I just run this script from cron pointed at the directory I keep my directories of active docker containers and their compose files:

#/bin/sh for d in /home/USERNAME/stacks/*/ do (cd "$d" && docker compose pull && docker compose up -d --force-recreate) done; for e in /home/USERNAME/dockge/ do (cd "$e" && docker compose pull && docker compose up -d --force-recreate) done;

docker image prune -a -f

[-] tristan@aussie.zone 4 points 9 months ago

Not exactly what you're asking but you can push specific images to a private repo to keep specific versions... Then you can just use the cleanup tag or prune to clear them off the system and if you want to pull them again it won't need to download it from the internet

[-] haui_lemmy@lemmy.giftedmc.com 1 points 9 months ago

Hmmmm… thats pretty cool. Thanks for the suggestion.

this post was submitted on 22 Jan 2024
12 points (92.9% liked)

Selfhosted

39665 readers
131 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 1 year ago
MODERATORS