Command when you want to erase all Docker images and containers cleanly and start over

Docker I'm not used to it yet, and I recreate it many times every time I build an initial development environment. .. If you recreate it many times, you will end up with similar names, and you often want to wipe it out, so make a note of the command at that time.

Stop all containers

terminal


PS C:\Users\607> docker stop $(docker ps -aq)

The stopped container ID is output

Output log


b900982a522d

Stop all networks

terminal


> docker system prune

The log will be output for the number of valid networks.

terminal


WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N] y
Deleted Containers:
b900982a522d3b706885a57cd3ae04f1e5e72266a230a9ed5d746fd67e9fb98c

Deleted Images:
deleted: sha256:917f7b2666d566d786c7a87d88c3a526ae73328b58883dd03ac56ac0c80892b1
deleted: sha256:0b7df1af6007d6a4579dae5458781967fe4f7541c25c50db585956d05d183cf0
deleted: sha256:042d7491666f0d7608fe6cfe54f7231818c3346c8f169a3edae50be677a4ba83
...

Deleted build cache objects:
reiknr169oxc59f9jy7hzp7tc
4olrdqcoqku9didqkquggjepb
ulylctcvpthkhx6l9erfchllz
...
Total reclaimed space: 1.574GB

Delete all images

terminal


> docker rmi -f $(docker images -aq)

Something that is as long as the image is output

Output log


Untagged: vueapp:0.0.1
Deleted: sha256:a66b8502954033b2e9052e5b2a25dabc3a5d6d03de1ca2dd4c5c0e3b47ce260f
Untagged: httpd:latest
Untagged: httpd@sha256:b82fb56847fcbcca9f8f162a3232acb4a302af96b1b2af1c4c3ac45ef0c9b968
Deleted: sha256:3dd970e6b110c8cbcec63e05a91e3cefd23c76a780fcb78c33979153f044b2d4
Deleted: sha256:92ed257f355234f3e6173699f2ef99363a5babec07a6b9178b2b1afb57214c55
Deleted: sha256:b57fd9052964b1f8e16ba5e3785018ba52de527c6aba686bb3845581ca4b77d7
...

With this, even if you make many mistakes, you can start over with a clean mind.

Recommended Posts

Command when you want to erase all Docker images and containers cleanly and start over
[Docker] Magic command when you want to wipe out none image
When you want to explicitly write OR or AND with ransack
docker-compose.yml when you want to keep mysql running with docker
Docker all containers, images (stopped, deleted)
One liner to delete all Docker images
Note: [Docker] How to start and stop
When you want to bind InputStream in JDBI3
When you want to use the method outside
Command to stop or delete all Docker resources
[Ruby] When you want to replace multiple characters
An introductory book to read when you start Rails
Verification of the relationship between Docker images and containers
When you want to dynamically replace Annotation in Java8