bashdockerdocker-cli

get image ids that not have any running container in docker cli


Is it possible to output the list of image ids that the container is not currently running? This command prints the id list of all the images in the output, but I only want the images that do not have an active container.

docker images -q

Finally, I want to remove the images that do not have an active container delete HDD so that the limited space of the server is not full. Currently, I am using this command docker rmi $(docker images -q), because some of the images have an active container, an error is encountered and the cd job fails. If you know of a bash script that can help, add it.


Solution

  • There is a docker command that deletes images that do not have an associated running container:

    You can add the -f or --force flag to prune the images and not prompt for confirmation

    You could use this in a scheduled bash script to keep your drive tidy