How to clear obsolete docker images created via Jenkins CI/CD?
I have created a CI/CD Jenkins Pipeline which does the following tasks
While the entire process works well. I am looking for a solution for a couple of scenarios.
One way of addressing this issue is to have a different jenkins job especially for the purpose of deleting older images.
That job would probably trigger on some appropriate schedule , say every night, once a week and so on, depending on how quickly you're worried you'll run out of space.
As to how you would delete the images, take a look at the docker image prune
command, with the --filter
option, as explained in this answer . That will allow you to only delete images, for example, older than 7 days, etc.
Hope that helps!
I think below should be the way to go forward
Find all the containers
docker ps -a -f "your condition"
Then stop and remove all containers which you found with below commands
docker stop "container name" docker rm "container name"
find all dangling images
docker images -f "dangling=true"
Remove all images
docker rmi "image name"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.