How to remove all local Docker Docker images

I recently started using Docker and never really figured out what instead ctrl-c

or docker-compose stop

should I use docker-compose down

to get rid of my experiments. Now I have a large number of unneeded docker images.

Is there a flag I can run to remove all local images and docker containers?

Something like the docker rmi --all --force

-all flag doesn't exist, but I'm looking for something with a similar idea.

+84


source to share


8 answers


To remove all containers, including its volumes,

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

      

To remove all images,



docker rmi -f $(docker images -a -q)

      

Remember that before deleting all images from which these containers were created, you must remove all containers.

+154


source


Use this to remove everything :

docker system prune -a --volumes

      

Remove all unused containers, volumes, networks and images



WARNING! This will remove:
    - all stopped containers
    - all networks not used by at least one container
    - all volumes not used by at least one container
    - all images without at least one container associated to them
    - all build cache

      

https://docs.docker.com/engine/reference/commandline/system_prune/#extended-description

+64


source


docker image prune -a

Delete all unused images, not just dangling ones. Add a parameter -f

to strength.

Local docker version: 17.09.0-ce, Git commit: afdb6d4, OS / Arch: darwin / amd64

$ docker image prune -h
Flag shorthand -h has been deprecated, please use --help

Usage:  docker image prune [OPTIONS]

Remove unused images

Options:
  -a, --all             Remove all unused images, not just dangling ones
      --filter filter   Provide filter values (e.g. 'until=<timestamp>')
  -f, --force           Do not prompt for confirmation
      --help            Print usage

      

+9


source


To remove all images:

docker rmi -f $(docker images -a | awk {'print $3'})

      

Explanation:

docker images -a | awk {'print $ 3'}

This command will return the entire image id and then use it to delete the image using its id.

+2


source


Simple and convenient commands

Delete all images

docker rmi $(docker images -a)

      

Remove containers that are in exit state

docker rm $(docker ps -a -f status=exited -q)

      

Remove containers that are in the created state

docker rm $(docker ps -a -f status=created -q)

      

NOTE: remove all containers then remove images

+2


source


You can try like this:

docker system prune

      

0


source


To remove all images:

docker rmi $(docker images -a -q)

      

where -a is everything and -q only returns image IDs

To remove unused images and containers:

docker system prune

      

be careful, as if you are using Docker Swarm and your local machine is joining the remote Swarm (as administrator / worker) your local machine will be a deployed repo. doing this thus removes the deployed images.

0


source


Delete without calling docker:

rm -rf /var/lib/docker

      

This is not recommended if you can run Docker normally, but if for some reason you don't want to, this will delete all huge files as well.

0


source







All Articles