To clean up the docker system there's the useful command
docker system prune -a
with its various options. I find myself often executing that to clean up the mess I've made when trying out different things in development, only to later re-download a bunch of images. This normally takes a long time (5-10 minutes) in my use cases, and unnecessarily hogs the bandwidth of the image libraries I use.
What I'd like is to know if there is a simple way to prevent certain images (ones that I know I will need again in the near future) from being pruned while still retaining the convenience of pruning the docker system in a single command?
One way I could do this is start a container from the images I want to keep before pruning, and then prune, but that defeats the convenience of a one-liner above. In addition, those containers need stopping and removing after pruning as they are an unnecessary burden on my resources at that point.
Is there a simple(r) way to do this?
CodePudding user response:
You can make your own images and LABEL them like this Dockerfile:
FROM ubuntu:20.04
LABEL myimage=keepit
You build this Dockerfile with docker build -t myubuntu .
And then you can use filter for this label to not prune it: docker prune -a --filter label!="myimage=keepit"
Docs: https://docs.docker.com/engine/reference/commandline/system_prune/#filtering