We frequently spin up some quick exploratory docker-based projects for a day or two that we'd like to quickly and easily discard when done, without disturbing our primary ongoing containers and images.
At any point in time we have quite a few 'stable' docker images and containers that we do NOT want to rebuild all the time.
How can one remove all the images and containers associated with the current directory's Dockerfile and docker-compose.yml file, without disturbing other projects' images and containers?
(All the Docker documentation I see shows how to discard them ALL, or requires finding and listing a bunch of IDs manually and discarding them manually. This seems primitive and time-wasting... In a project folder, the Dockefile and docker-compose.yml file have all the info needed to identify "all images and images that were created when building and running THIS project" so it seems there would quick command to remove that project's docker dregs when done.)
As an example, right now I have rarely revised Docker images and containers for several production Rails 5 apps I'd like to keep untouched, but a half-dozen folders with short-term Rails 6 experiments that represent dozens of images and containers I'd like to discard.
Is there any way to tell Docker... "here's a Dockerfile and a docker-compose,yml file, stop and remove any/all containers and images that were created by them?"
docker inspect $image
after each build will give you theRootFS.Layers
array. Again, shared layers will be a problem.