Say you have accumulated number of docker images and containers which are no longer used. The simplest way on how to remove all unused docker images and containers us by using the docker
command with a prune
argument.
So for example to remove all stopped containers which were created 2 or more weeks ago ( 336 hours ) use the following docker
command with until
filter:
# docker container prune --filter "until=336h"
Furthermore to delete all images without at least one container associated to them which were created 2 or more weeks ago ( 336 hours ) execute:
# docker image prune -a --filter "until=336h"
Note: Make sure to delete/prune containers before images to maximize disk space recovery size.