Deleting Containers and Images from Docker

Posted by coffeetechgaff on April 10, 2017

If you want to delete specific image or container from docker registry, it is very easy to delete just by writing following command.

for container:

                      docker rm [container name]
                    

for image:

                      docker rmi [image id/name]
                    

What about if you want to delete all the images and containers from your docker? It is very easy to remove all container and images at once as well. Please execute following command to remove all containers from docker

                      docker rm $(docker ps -a -q)
                    

This command won’t delete running containers. You need to stop all the running containers if you want to delete running container as well.

On the other hand, if you want to delete all the images from docker registry, you can run following command.

                      docker rmi $(docker images -q)
                    

Sometimes above command won’t delete all the images from docker. If it did not delete some images, you can run following command to force delete.

                      docker rmi -f $(docker images -q)
                    

reference: https://github.com/docker/docker/issues/928#issuecomment-23538307