docker images output manipulation

Viewed 73

I'm trying to delete each docker image that it's name == none in my system.

I have tried this

for image in $(docker images  | grep none); do echo $image; done

But this gives me the output of each column like that:

<none>      
<none>      
a20d00ca4041
19          
minutes     
ago         
227MB       

I want it like that:

<none>            <none>              a20d00ca4041        20 minutes ago      227MB

So i can delete delete the image by it's id.

Any help ?

2 Answers

Use awk command instead

docker images | grep "none" | awk '{print $3}' | xargs docker rmi

Based on dov answer this make more sense to me:

EDIT: As Mark suggested this is shorter and cleaner.

docker rmi $(docker images | awk ' /none/ {print $3}')
Related