Over time,Docker can accumulate stopped containers, unused images, orphaned volumes, and more. This can quickly fill up your disk.
Fortunately,Docker offers simple commands to clean things up without having to delete everything manually.
Basic commands for cleaning up
- Delete all stopped containers:
docker container prune
- Delete all unused images:
docker image prune
- Delete all unused volumes:
docker volume prune
- Delete all unused networks:
docker network prune
Beginner tip: You can do it all at once with:
docker system prune
- Add the option
-ato delete all unused images, not just the intermediate ones:
docker system prune -a
Warning: This command may delete images still in use by certain projects if you are not careful.
Best practices
- Clean up regularly, especially on development machines.
- Check disk space before and after with
docker system df. - Do not use
-aon a production server without checking the active containers.
Quick example:
docker system df
docker system prune -a
docker system df
Youβll instantly see the freed-up space!