Optimizing Disk Space with Docker Cleanup

yevgenp
1 min readDec 30, 2023

Docker, a robust tool for containerizing applications, efficiently manages resources but can consume considerable disk space. Employ these commands to tidy up and optimize your Docker environment:

1. Cleanup Docker Images

Remove all unused Docker images:

docker image prune -a

For solely removing dangling images (those unassociated with any containers):

docker image prune

Filter images by age for removal (e.g., images older than 30 days):

docker image prune -a --filter "until=720h"

2. Cleanup Docker Containers

Remove all stopped containers:

docker container prune

Forcefully remove all containers (stopped and running):

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

3. Cleanup Docker Volumes

Remove all unused volumes:

docker volume prune

Filter volumes, eliminating those unassociated with containers:

docker volume prune --filter "dangling=true"

4. Docker Cleanup Everything

To comprehensively clean up all unused images, stopped containers, and volumes:

docker system prune -a --volumes

Note: Exercise caution when using system-wide cleanup commands as they remove all unused components.

Utilize these Docker cleanup commands judiciously to reclaim disk space and maintain a streamlined development environment.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

yevgenp
yevgenp

Written by yevgenp

Lead Software Engineer | Tech Lead | Software Architect | Senior Software Engineer | IT Career Coach, Mentor & Consultant

No responses yet

Write a response