-
-
Save anildigital/862675ec1b7bccabc311 to your computer and use it in GitHub Desktop.
docker rmi $(docker images -q -f dangling=true) |
You will have the error message in case of no dangling images. The version without the error:
docker images -qf dangling=true | xargs docker rmi
xargs
will need --no-run-if-empty
(-r
) to bypass executing docker rmi
with no arguments. So:
docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi
--no-run-if-empty
Not on OS X, though.
Some images can't be removed without -f option
docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi -f
$ docker images --quiet --filter=dangling=true | xargs docker rmi -f
(on OSX, dunno if dangerous -f cmd)
docker rmi $(docker images -q -f dangling=true)
Doesn't work in Windows cmd
This works for Windows cmd:
FOR /f "tokens=*" %i IN ('docker images -q -f "dangling=true"') DO docker rmi %i
If you have PowerShell you can use this:
docker rmi $(docker images -q -f dangling=true)
Using this for any linux/osx system:
if docker images -f "dangling=true" | grep ago --quiet; then
docker rmi -f $(docker images -f "dangling=true" -q)
fi
You do that easier:
docker image prune
@MBlagui, bravo!
@MBlagui you're my hero for this
docker container prune works well too, thanks!
docker container prune ; docker images prune
The docs say docker prune "removes all dangling images". And it even issues a warning "this will remove all dangling images". So why does it not remove mine?
ubuntu@ip-172-31-26-48:~$ docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0 B
ubuntu@ip-172-31-26-48:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
simonm3/registrm latest bd3ef6d73785 7 minutes ago 468 MB
simonm3/registr latest 7dd15943671b 2 hours ago 2.51 GB
simonm3/registrm <none> f8f22986e85a 45 hours ago 2.93 GB
simonm3/registrm <none> c1b9d8606371 45 hours ago 2.93 GB
simonm3/registrm <none> f1ca97467106 45 hours ago 2.93 GB
simonm3/registr <none> 6a5af88f93a7 45 hours ago 4.42 GB
simonm3/registrm <none> 93dc81b0fa7a 45 hours ago 2.93 GB
simonm3/registrm <none> dbc50510d499 45 hours ago 2.93 GB
simonm3/registr <none> 0101ca5d4a25 45 hours ago 4.42 GB
simonm3/registrm <none> d8f85df39f0a 46 hours ago 2.93 GB
simonm3/registrm <none> 053892e9798b 46 hours ago 2.93 GB
simonm3/registrm <none> 3845056cf241 46 hours ago 2.92 GB
simonm3/registr <none> 349ef3c589bd 46 hours ago 4.42 GB
simonm3/registrm <none> 5dcbb0db4710 2 days ago 2.92 GB
simonm3/registr <none> e403f74861f6 2 days ago 4.32 GB
simonm3/registr <none> c12ca8819c24 5 days ago 4.32 GB
simonm3/registrm <none> 4bb8ed8154b7 6 days ago 2.92 GB
ubuntu@ip-172-31-26-48:~$ docker images -q -f dangling=true
f8f22986e85a
c1b9d8606371
f1ca97467106
6a5af88f93a7
93dc81b0fa7a
dbc50510d499
0101ca5d4a25
d8f85df39f0a
053892e9798b
3845056cf241
349ef3c589bd
5dcbb0db4710
e403f74861f6
c12ca8819c24
4bb8ed8154b7
@simonm3 you probably want to run docker container prune
- otherwise docker still thinks they are being run by a stopped container
docker rmi -f $(docker images --quiet --filter "dangling=true")
nice jobs
Some images can't be removed without -f option
docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi -f
This works perfect, does the job
The "full" command would be written as such (easier to understand)