0

I am unable to delete all my local docker containers or images and below is the error I am getting. Can you please suggest what am I doing wrong ?

docker rmi $(docker ps -a -q)

unknown shorthand flag: 'a' in -a

See 'docker rmi --help'.<\br>

Ashwin Dora
  • 115
  • 1
  • 12
  • duplicate of https://stackoverflow.com/questions/32723111/how-to-remove-old-and-unused-docker-images – Akshay barahate Apr 23 '19 at 14:13
  • Possible duplicate of [How to remove old and unused Docker images](https://stackoverflow.com/questions/32723111/how-to-remove-old-and-unused-docker-images) – Akshay barahate Apr 23 '19 at 14:13

1 Answers1

2

docker ps is pulling a list of the containers you have, not the images, and rmi is used for removing images, not containers.

Use docker rm $(docker ps -a -q)

If you want to clean up your docker space, check out the prune command, for example:

docker system prune

docker image prune

docker container prune

Nordle
  • 2,915
  • 3
  • 16
  • 34
  • I am trying to delete all my containers first and that's where I am using 'docker rm $(docker ps -a -q)' and once done with it I thought of using 'docker rmi $(docker images -q)' to delete the images. But the problem I am facing in deleting all the containers first. Logically it should work and the command is pretty straightforward. – Ashwin Dora Apr 23 '19 at 14:17
  • So i deleted all my containers manually one by one and used below command to delete all the images 'docker rmi $(docker images -q)' . It worked – Ashwin Dora Apr 23 '19 at 14:21
  • 2
    Please read my answer correctly, you are using the command `docker rmi` (which removes *images*) in conjunction with `docker ps` which lists *containers*. If you want to remove *containers* then use: `docker rm $(docker ps -a -q)` – Nordle Apr 23 '19 at 14:23
  • 1
    You are right. Ooops I overlooked the problem. Thanks – Ashwin Dora Apr 24 '19 at 13:18