Showing posts with label Docker maintenance. Show all posts
Showing posts with label Docker maintenance. Show all posts

Thursday, March 27, 2025

Safely Removing Local Docker Images Without Affecting Remote Repositories

You want to remove all local images that belong to username/reponame regardless of their tag, but DO NOT delete anything from Docker Hub (remote). Only clean local.

Here is the safest way:


docker images "username/reponame" --format "{{.Repository}}:{{.Tag}}" | xargs -r docker rmi


✅ Explanation:

  • It will only delete local images of username/reponame:*

  • Remote images on Docker Hub are untouched

  • Safe to run multiple times (won't fail if already deleted)


 You just want to remove only the <none> tagged images from username/reponame.

Here is the exact command for your case:


docker images "username/reponame" --filter "dangling=true" --format "{{.ID}}" | xargs -r docker rmi


✅ Explanation:

  • --filter "dangling=true" targets images with <none> as tag

  • --format "{{.ID}}" gets only their Image ID

  • xargs -r docker rmi safely removes them if any exist

  • Safe to run multiple times