Bobcares

Docker Prune Containers and Images | How-to

by | Apr 4, 2022

Docker Prune containers and images commands and options are made easy with this handy guide by our experts. 

 

At Bobcares, we offer solutions for every query, big and small, as a part of our Server Management Services.

 

Let’s take a look at how our Support Team is ready to help customers prune Docker containers and images.

 

How to prune Docker Containers and Images

If you are looking for a way to prune containers and images, you have come to the right place. According to our Support Team, the docker image prune [OPTIONS] command cleans up images not in use. Furthermore, the command cleans up only dangling images by default.

 

In other words, an image that is not referenced or tagged by any container. Hence, the following command will remove dangling images:

 
 docker image prune
 

How to Prune Images

If we want to remove images, not in use by existing containers, we have to use the following commands:

 
 docker image prune -a
 

By default, a prompt pops up asking us to continue. We can bypass this prompt by using the -f or –force flag.

 

The options of the docker image prune command include:

 

Docker Prune Containers and Images

 

The filtering flag format is “key=value”. In case there is more than one filter, we can pass multiple flags as seen below:

 
--filter "bif=baz" --filter "foo=bar"
 

Currently, the command supports the following filters:

 
  • until ()
     

    This filter removes only those images created before the given timestamp

  • label (label=, label!=, label==, or label!==)
     

    This filter removes images with specific labels.

 

Furthermore, the until filter can be either date formatted timestamps, Unix timestamps, or Go duration strings in relation to the daemon machine’s time.

 

Additionally, we can limit the images we are pruning by using the –filter flag. For instance, if we want to prune images to come into creation from the last 12 hours, we would use the following command:

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

How to Prune Containers

When we stop a container, it continues to exist, unless we started it with –rm flag. According to our Support Team, we can view all containers on the Docker host, including the stopped containers with the following command:

 
 docker ps -a
 

The stopped containers take up disk space, so it is a good idea to clean up with the docker container prune command.

 
 docker container prune [OPTIONS]
 

Docker Prune Containers and Images

 

The filtering flag format is “key=value”. In case there is more than one filter, we can pass multiple flags as seen below:

 
--filter "bif=baz" --filter "foo=bar"
 

Currently, the command supports the following filters:

 
  • until ()
     

    This filter removes only those images created before the given timestamp

  • label (label=, label!=, label==, or label!==)
     

    This filter removes images with specific labels.

 

Furthermore, the until filter can be either date formatted timestamps, Unix timestamps, or Go duration strings in relation to the daemon machine’s time.

 

Additionally, we can limit the images we are pruning by using the –filter flag. For instance, if we want to prune images to come into creation from the last 12 hours, we would use the following command:

 
 docker container prune -a --filter "until=12h"
 

[Looking for a solution to another query? We are just a click away.]

 

Conclusion

To sum up, our skilled Support Engineers at Bobcares demonstrated how to prune Docker containers and images.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.