Table of Contents
What is Docker system prune?
How to use basic commands?
Clean up more thoroughly: add --all parameters
Clean the build cache
Tips and notes
Home Operation and Maintenance Docker How do you use Docker system prune to clean up unused resources?

How do you use Docker system prune to clean up unused resources?

Jun 27, 2025 am 12:33 AM

Docker system prune is a command to clean unused resources that delete stopped containers, unused networks, dangling images, and build caches. 1. Running docker system prune by default will clean up the hanging images and prompt for confirmation; 2. Add the -f parameter to skip confirmation; 3. Use --all to delete all unused images; 4. Use --filter to clean the cache by time; 5. Execute this command regularly to help maintain the clean environment and avoid insufficient disk space.

Docker system prune is a very practical command that can help you quickly clean up Docker resources that are no longer used. If you find that local Docker takes up too much disk space, or want to maintain it regularly to keep the environment clean, this command is your first choice.

What is Docker system prune?

docker system prune is a system-level cleaning command provided by Docker to delete all unused resources, including:

  • Stopped container
  • Networks not used by any container
  • dangling mirror (i.e. mirrors that have no tags and are not referenced by any container)
  • Build cache (also included in newer versions by default)

Execution of this command will not affect the running container, used mirrors, or persisted data volumes, so it is relatively safe.

How to use basic commands?

The easiest way to use it is to run it directly:

 docker system prune

After running, you will be prompted to confirm whether to continue. Enter y to enter to start cleaning.

If you want to skip the confirmation step (for example, use it in a script), you can add the -f or --force parameter:

 docker system prune -f

Clean up more thoroughly: add --all parameters

By default, docker system prune will only delete the dangling image. If you want to delete all unused images (including those with tags but not referenced by containers), you can add the --all parameter:

 docker system prune --all

Note: This will delete more images. It is recommended to confirm which images you need to keep before the operation.

Clean the build cache

Starting with Docker 20.x, system prune also cleans the build cache by default. If you just want to clean the build cache without cleaning other resources, you can use:

 docker builder prune

To clean all build caches and unused resources at the same time, you can add --filter to control retention time, such as cleaning only caches that exceed 24 hours:

 docker builder prune --filter "until=24h"

Tips and notes

  • Execution of docker system prune regularly can avoid insufficient disk space.
  • If you have a lot of old images or build caches, cleaning may take a little time.
  • Be careful when using -a or --all , it may delete more than you expected.
  • If you use it in a CI/CD environment, it is recommended to add -f to automatically confirm and cooperate with the timing tasks.

Basically that's it. With docker system prune , you can easily keep the Docker environment clean and refreshing.

The above is the detailed content of How do you use Docker system prune to clean up unused resources?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do you create a custom Docker network driver? How do you create a custom Docker network driver? Jun 25, 2025 am 12:11 AM

To create a custom Docker network driver, you need to write a Go plugin that implements NetworkDriverPlugin API and communicate with Docker via Unix sockets. 1. First understand the basics of Docker plug-in, and the network driver runs as an independent process; 2. Set up the Go development environment and build an HTTP server that listens to Unix sockets; 3. Implement the required API methods such as Plugin.Activate, GetCapabilities, CreateNetwork, etc. and return the correct JSON response; 4. Register the plug-in to the /run/docker/plugins/ directory and pass the dockernetwork

What is Docker Compose, and when should you use it? What is Docker Compose, and when should you use it? Jun 24, 2025 am 12:02 AM

The core feature of DockerCompose is to start multiple containers in one click and automatically handle the dependencies and network connections between them. It defines services, networks, volumes and other resources through a YAML file, realizes service orchestration (1), automatically creates an internal network to make services interoperable (2), supports data volume management to persist data (3), and implements configuration reuse and isolation through different profiles (4). Suitable for local development environment construction (1), preliminary verification of microservice architecture (2), test environment in CI/CD (3), and stand-alone deployment of small applications (4). To get started, you need to install Docker and its Compose plugin (1), create a project directory and write docker-compose

How do you create a Docker volume? How do you create a Docker volume? Jun 28, 2025 am 12:51 AM

A common way to create a Docker volume is to use the dockervolumecreate command and specify the volume name. The steps include: 1. Create a named volume using dockervolume-createmy-volume; 2. Mount the volume to the container through dockerrun-vmy-volume:/path/in/container; 3. Verify the volume using dockervolumels and clean useless volumes with dockervolumeprune. In addition, anonymous volume or binding mount can be selected. The former automatically generates an ID by Docker, and the latter maps the host directory directly to the container. Note that volumes are only valid locally, and external storage solutions are required across nodes.

How do you specify environment variables in a Docker container? How do you specify environment variables in a Docker container? Jun 28, 2025 am 12:22 AM

There are three common ways to set environment variables in a Docker container: use the -e flag, define ENV instructions in a Dockerfile, or manage them through DockerCompose. 1. Adding the -e flag when using dockerrun can directly pass variables, which is suitable for temporary testing or CI/CD integration; 2. Using ENV in Dockerfile to set default values, which is suitable for fixed variables that are not often changed, but is not suitable for distinguishing different environment configurations; 3. DockerCompose can define variables through environment blocks or .env files, which is more conducive to development collaboration and configuration separation, and supports variable replacement. Choose the right method according to project needs or use multiple methods in combination

What are Docker containers, and how are they run? What are Docker containers, and how are they run? Jul 01, 2025 am 12:13 AM

Docker containers are a lightweight, portable way to package applications and their dependencies together to ensure applications run consistently in different environments. Running instances created based on images enable developers to quickly start programs through "templates". Run the dockerrun command commonly used in containers. The specific steps include: 1. Install Docker; 2. Get or build a mirror; 3. Use the command to start the container. Containers share host kernels, are lighter and faster to boot than virtual machines. Beginners recommend starting with the official image, using dockerps to view the running status, using dockerlogs to view the logs, and regularly cleaning resources to optimize performance.

How do you use Docker system prune to clean up unused resources? How do you use Docker system prune to clean up unused resources? Jun 27, 2025 am 12:33 AM

Dockersystemrune is a command to clean unused resources that delete stopped containers, unused networks, dangling images, and build caches. 1. Run dockersystemrune by default to clean up the hanging mirror and prompt for confirmation; 2. Add the -f parameter to skip confirmation; 3. Use --all to delete all unused images; 4. Use --filter to clean the cache by time; 5. Execute this command regularly to help maintain the clean environment and avoid insufficient disk space.

What is the purpose of the EXPOSE instruction in a Dockerfile? What is the purpose of the EXPOSE instruction in a Dockerfile? Jul 01, 2025 am 12:45 AM

EXPOSE is used in Dockerfile to declare the network port the container will listen for at runtime, but it will not be published automatically to the host. Its core role is to provide documentation and configuration tips to help developers and tools understand the ports used by the application. To make the port accessible from the outside, you still need to use the -p parameter to map when running the container, for example: dockerrun-p8080:80my-web-app. The main reasons for using EXPOSE include improving clarity, supporting tool integration, and following best practices. Containers can directly access each other's exposed ports in the same custom network, but to access them on the host, the ports must be published explicitly. A common error is that you forget to map the port when running the container, causing the service to fail.

How does Docker differ from traditional virtualization? How does Docker differ from traditional virtualization? Jul 08, 2025 am 12:03 AM

The main difference between Docker and traditional virtualization lies in the processing and resource usage of the operating system layer. 1. Docker containers share the host OS kernel, which is lighter, faster startup, and more resource efficiency; 2. Each instance of a traditional VM runs a full OS, occupying more space and resources; 3. The container usually starts in a few seconds, and the VM may take several minutes; 4. The container depends on namespace and cgroups to achieve isolation, while the VM obtains stronger isolation through hypervisor simulation hardware; 5. Docker has better portability, ensuring that applications run consistently in different environments, suitable for microservices and cloud environment deployment.

See all articles