I am trying to remove running containers and delete all downloaded images by using below commands:
docker ps -aq | xargs docker rm -f
docker images -aq | xargs docker rmi -f
But I got this
"docker rm" requires at least 1 argument.
See 'docker rm --help'.
Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]
and
"docker rmi" requires at least 1 argument.
See 'docker rmi --help'.
Usage: docker rmi [OPTIONS] IMAGE [IMAGE...]
this is my environment
Client:
Version: 17.09.0-ce
API version: 1.32
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:42:18 2017
OS/Arch: linux/amd64
Server:
Version: 17.09.0-ce
API version: 1.32 (minimum version 1.12)
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:40:56 2017
OS/Arch: linux/amd64
Experimental: false
docker-compose version 1.16.1, build 6d1ac21
docker-py version: 2.5.1
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t 3 May 2016
Is something wrong here? please help! Thanks
Use -r
with xargs
, it means not to execute if empty:
docker ps -aq | xargs -r docker rm -f
docker images -aq | xargs -r docker rmi -f
You need to first stop running container then remove them
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
For images try to remove dangling images
docker rmi $(docker images -f dangling=true -q)
To remove all images use
docker rmi $(docker images -q)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With