DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,503 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
kay-adamof
kay-adamof

Posted on

How to remove all the disk usage occupied by Docker

If you are doing hard works with Docker, you would be noticed that the Docker uses many ammounts of your local storage and will happen the disk shortage. In that situation, you are probably want to delete all the disk usage occupied by Docker, but how should we do? I'll introduce you guys the 4 commands to clear the disk usage.

First of all, Let's check out the Docker's disk usage.

How to check out the disk usage by Docker

docker system df

# docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          6         2         1.758GB   1.013GB (57%)
Containers      2         0         1.937MB   1.937MB (100%)
Local Volumes   11        3         391.1MB   53.85MB (13%)
Build Cache     141       0         1.003GB   1.003GB
Enter fullscreen mode Exit fullscreen mode

We are able to see 4 types of disk usage via docker system df.And next, we are going to delete these disk usage individually.

How to delete all the Docker Images

docker rmi $(docker images -q)

rmi: ReMove Images
$(docker images -q): List all the image IDs

How to delete all the Docker Containers

docker rm $(docker ps -a -q)

rm: ReMove containers
$(docker ps -a -q): List all the container IDs

How to delete all the Docker Local Volumes

docker volume rm $(docker volume ls -qf dangling=true)

volume rm: Volume, ReMove
$(docker volume ls -qf dangling=true): List all the volume names including dangling ones

You see what the 'dangling' is

How to delete all the Docker Build Cache

docker builder prune -a

builder prune -a: remove all build cache

Wrap up

You are able to run these four commands to clear all the disk usage by Docker:

docker rmi $(docker images -q)
docker rm $(docker ps -a -q)
docker volume rm $(docker volume ls -qf dangling=true)
docker builder prune -a

Top comments (0)

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›