DEV Community

Simon Mannes
Simon Mannes

Posted on • Originally published at mannes.tech on

2 2

A Simple Way to Clean up Docker

Have you ever had a full hard drive because of Docker? I had. All those old Docker containers, images, and volumes take up so much space. I used commands like docker stop $(docker ps -a -q) and docker rm $(docker ps -a -q)  to remove all containers and images.

But newer Docker versions (Docker with API version 1.25+) have this handy cleanup command:

docker system prune --volumes
Enter fullscreen mode Exit fullscreen mode

It cleans up all stopped containers, unused networks, dangling images, and the build cache. The --volumes flag also removes all unused volumes. You can skip the "are you sure" prompt by using the -f or --force flag

Beforehand, you will want to stop all containers using this command:

docker container stop $(docker container ls -aq)
Enter fullscreen mode Exit fullscreen mode

And voilá! You have a clean local Docker installation.

Bonus tips:

  • Find out how much space Docker takes on your system with: docker system df
  • Use the until filter to only clean up stuff created more than, e.g., two days ago: docker system prune --filter "until=48h" (Docker API version 1.28+; use docker version to find out the versions of your client and daemon)
  • Only clean up containers created more than two days ago: docker container prune --filter "until=48h"

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs