Open ghost opened 5 years ago
We need to look at options, and to see what makes sense (and if we can take an equivalent approach on other commands).
Comparing with rm
on Linux
rm ""
rm: can't remove '': No such file or directory
rm -f ""
echo $?
0
For rm -f
we already produce a "successful" exist status, but still print a warning if the container didn't exist;
docker rm -f nosuchcontainer
Error: No such container: nosuchcontainer
echo $?
0
Description
Commands
docker rm
anddocker rmi
fail, returning an error code and breaking the command chain. Since these commands effectively do nothing if no arguments are given, there is no reason for them to fail.Use case
To remove all the images you need first to remove all the containers but this will fail if there are no containers. The expected effect of
docker rm $(docker ps -a -q)
is already achieved, so it should not fail. The same thing withdocker rmi $(docker images -q)
.