How to delete docker images in Jenkins Job

Viewed 16175

I want to delete the remains of some Docker-operations from within Jenkins.

But somehow the following line does not work...

The issue seems to be with the parenthesis.

Any advice?

if [ docker images -f dangling=true -q|wc -l > 0 ]; then docker rmi --force $(docker images -f dangling=true -q);fi
4 Answers

Remove Dangling Images

Use -xargs will need --no-run-if-empty (-r) to bypass executing docker rmi with no arguments

docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi

Use normar bash comand to check and delete

 if docker images -f "dangling=true" | grep ago --quiet; then
    docker rmi -f $(docker images -f "dangling=true" -q)
 fi
Related