How to remove unused docker containers
https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes
How To Remove Docker Images, Containers, and Volumes | DigitalOcean
2016-11-17
Melissa Anderson
<div><div><h3>Introduction</h3>
<p><a href="https://www.docker.com/">Docker</a> makes it easy to wrap your applications and services in containers so you can run them anywhere. As you work with Docker, however, itâs also easy to accumulate an excessive number of unused images, containers, and data volumes that clutter the output and consume disk space.</p>
<p>Docker gives you all the tools you need to clean up your system from the command line. This cheat sheet-style guide provides a quick reference to commands that are useful for freeing disk space and keeping your system organized by removing unused Docker images, containers, and volumes.</p>
<p><strong>How to Use This Guide:</strong></p>
<ul>
<li>This guide is in cheat sheet format with self-contained command-line snippets.</li>
<li>Jump to any section that is relevant to the task you are trying to complete.</li>
</ul>
<p><strong>Note:</strong> The command substitution syntax, <code><mark>command</mark> $(<mark>command</mark>)</code>, used in the commands is available in many popular shells, such as <a href="https://www.gnu.org/software/bash/">bash</a>, <a href="https://www.zsh.org/">zsh</a>, and <a href="https://docs.microsoft.com/en-us/powershell/">Windows Powershell</a>.</p>
<h2>Purging All Unused or Dangling Images, Containers, Volumes, and Networks</h2>
<p>Docker provides a single command that will clean up any resources â images, containers, volumes, and networks â that are <em>dangling</em> (not tagged or associated with a container):</p>
<pre><code><ol><li>docker system prune
</li></ol>
</code></pre>
<p>To additionally remove any stopped containers and all unused images (not just dangling images), add the <code>-a</code> flag to the command:</p>
<pre><code><ol><li>docker system prune -a
</li></ol>
</code></pre>
<h2>Removing Docker Images</h2>
<h3>Remove one or more specific images</h3>
<p>Use the <code>docker images</code> command with the <code>-a</code> flag to locate the ID of the images you want to remove. This will show you every image, including intermediate image layers. When youâve located the images you want to delete, you can pass their ID or tag to <code>docker rmi</code>:</p>
<p><strong>List:</strong></p>
<pre><code><ol><li>docker images -a
</li></ol>
</code></pre>
<p><strong>Remove:</strong></p>
<pre><code><ol><li>docker rmi <mark>Image</mark> <mark>Image</mark>
</li></ol>
</code></pre>
<h3>Remove dangling images</h3>
<p>Docker images consist of multiple layers. Dangling images are layers that have no relationship to any tagged images. They no longer serve a purpose and consume disk space. They can be located by adding the filter flag <code>-f</code> with a value of <code>dangling=true</code> to the <code>docker images</code> command. When youâre sure you want to delete them, you can use the <code>docker image prune</code> command:</p>
<p><strong>Note:</strong> If you build an image without tagging it, the image will appear on the list of dangling images because it has no association with a tagged image. You can avoid this situation by <a href="https://docs.docker.com/engine/reference/commandline/build/#/tag-image--t">providing a tag</a> when you build, and you can retroactively tag an image with the <a href="https://docs.docker.com/engine/reference/commandline/tag/"><code>docker tag</code></a> command.</p>
<p><strong>List:</strong></p>
<pre><code><ol><li>docker images -f dangling=true
</li></ol>
</code></pre>
<p><strong>Remove:</strong></p>
<pre><code><ol><li>docker image prune
</li></ol>
</code></pre>
<h3>Removing images according to a pattern</h3>
<p>You can find all the images that match a pattern using a combination of <code>docker images</code> and <a href="https://www.digitalocean.com/community/tutorials/using-grep-regular-expressions-to-search-for-text-patterns-in-linux"><code>grep</code></a>. Once youâre satisfied, you can delete them by using <a href="https://www.digitalocean.com/community/tutorials/how-to-use-the-awk-language-to-manipulate-text-in-linux"><code>awk</code></a> to pass the IDs to <code>docker rmi</code>. Note that these utilities are not supplied by Docker and are not necessarily available on all systems:</p>
<p><strong>List:</strong></p>
<pre><code><ol><li>docker images -a | grep "<mark>pattern</mark>"
</li></ol>
</code></pre>
<p><strong>Remove:</strong></p>
<pre><code><ol><li>docker images -a | grep "<mark>pattern</mark>" | awk '{print $3}' | xargs docker rmi
</li></ol>
</code></pre>
<h3>Remove all images</h3>
<p>All the Docker images on a system can be listed by adding <code>-a</code> to the <code>docker images</code> command. Once youâre sure you want to delete them all, you can add the <code>-q</code> flag to pass the image ID to <code>docker rmi</code>:</p>
<p><strong>List:</strong></p>
<pre><code><ol><li>docker images -a
</li></ol>
</code></pre>
<p><strong>Remove:</strong></p>
<pre><code><ol><li>docker rmi $(docker images -a -q)
</li></ol>
</code></pre>
<h2>Removing Containers</h2>
<h3>Remove one or more specific containers</h3>
<p>Use the <code>docker ps</code> command with the <code>-a</code> flag to locate the name or ID of the containers you want to remove:</p>
<p><strong>List:</strong></p>
<pre><code><ol><li>docker ps -a
</li></ol>
</code></pre>
<p><strong>Remove:</strong></p>
<pre><code><ol><li>docker rm <mark>ID_or_Name</mark> <mark>ID_or_Name</mark>
</li></ol>
</code></pre>
<h3>Remove a container upon exiting</h3>
<p>If you know when youâre creating a container that you wonât want to keep it around once youâre done, you can run <code>docker run --rm</code> to automatically delete it when it exits:</p>
<p><strong>Run and Remove:</strong></p>
<pre><code><ol><li>docker run --rm <mark>image_name</mark>
</li></ol>
</code></pre>
<h3>Remove all exited containers</h3>
<p>You can locate containers using <code>docker ps -a</code> and filter them by their status: <code>created</code>, <code>restarting</code>, <code>running</code>, <code>paused</code>, or <code>exited</code>. To review the list of <code>exited</code> containers, use the <code>-f</code> flag to filter based on status. When youâve verified you want to remove those containers, use <code>-q</code> to pass the IDs to the <code>docker rm</code> command:</p>
<p><strong>List:</strong></p>
<pre><code><ol><li>docker ps -a -f status=exited
</li></ol>
</code></pre>
<p><strong>Remove:</strong></p>
<pre><code><ol><li>docker rm $(docker ps -a -f status=exited -q)
</li></ol>
</code></pre>
<h3>Remove containers using more than one filter</h3>
<p>Docker filters can be combined by repeating the filter flag with an additional value. This results in a list of containers that meet either condition. For example, if you want to delete all containers marked as either <code>created</code> (a state which can result when you run a container with an invalid command) or <code>exited</code>, you can use two filters:</p>
<p><strong>List:</strong></p>
<pre><code><ol><li>docker ps -a -f status=exited -f status=created
</li></ol>
</code></pre>
<p><strong>Remove:</strong></p>
<pre><code><ol><li>docker rm $(docker ps -a -f status=exited -f status=created -q)
</li></ol>
</code></pre>
<h3>Remove containers according to a pattern</h3>
<p>You can find all the containers that match a pattern using a combination of <code>docker ps</code> and <a href="https://www.digitalocean.com/community/tutorials/using-grep-regular-expressions-to-search-for-text-patterns-in-linux"><code>grep</code></a>. When youâre satisfied that you have the list you want to delete, you can use <a href="https://www.digitalocean.com/community/tutorials/how-to-use-the-awk-language-to-manipulate-text-in-linux"><code>awk</code></a> and <code>xargs</code> to supply the ID to <code>docker rm</code>. Note that these utilities are not supplied by Docker and are not necessarily available on all systems:</p>
<p><strong>List:</strong></p>
<pre><code><ol><li>docker ps -a | grep "<mark>pattern</mark>â
</li></ol>
</code></pre>
<p><strong>Remove:</strong></p>
<pre><code><ol><li>docker ps -a | grep "<mark>pattern</mark>" | awk '{print $1}' | xargs docker rm
</li></ol>
</code></pre>
<h3>Stop and remove all containers</h3>
<p>You can review the containers on your system with <code>docker ps</code>. Adding the <code>-a</code> flag will show all containers. When youâre sure you want to delete them, you can add the <code>-q</code> flag to supply the IDs to the <code>docker stop</code> and <code>docker rm</code> commands:</p>
<p><strong>List:</strong></p>
<pre><code><ol><li>docker ps -a
</li></ol>
</code></pre>
<p><strong>Remove:</strong></p>
<pre><code><ol><li>docker stop $(docker ps -a -q)
</li><li>docker rm $(docker ps -a -q)
</li></ol>
</code></pre>
<h2>Removing Volumes</h2>
<h3>Remove one or more specific volumes - Docker 1.9 and later</h3>
<p>Use the <code>docker volume ls</code> command to locate the volume name or names you wish to delete. Then you can remove one or more volumes with the <code>docker volume rm</code> command:</p>
<p><strong>List:</strong></p>
<pre><code><ol><li>docker volume ls
</li></ol>
</code></pre>
<p><strong>Remove:</strong></p>
<pre><code><ol><li>docker volume rm <mark>volume_name</mark> <mark>volume_name</mark>
</li></ol>
</code></pre>
<h3>Remove dangling volumes - Docker 1.9 and later</h3>
<p>Since the point of volumes is to exist independent from containers, when a container is removed, a volume is not automatically removed at the same time. When a volume exists and is no longer connected to any containers, itâs called a <em>dangling volume</em>. To locate them to confirm you want to remove them, you can use the <code>docker volume ls</code> command with a filter to limit the results to dangling volumes. When youâre satisfied with the list, you can remove them all with <code>docker volume prune</code>:</p>
<p><strong>List:</strong></p>
<pre><code><ol><li>docker volume ls -f dangling=true
</li></ol>
</code></pre>
<p><strong>Remove:</strong></p>
<pre><code><ol><li>docker volume prune
</li></ol>
</code></pre>
<h3>Remove a container and its volume</h3>
<p>If you created an unnamed volume, it can be deleted at the same time as the container with the <code>-v</code> flag. Note that this only works with <em>unnamed</em> volumes. When the container is successfully removed, its ID is displayed. Note that no reference is made to the removal of the volume. If it is unnamed, it is silently removed from the system. If it is named, it silently stays present.</p>
<p><strong>Remove:</strong></p>
<pre><code><ol><li>docker rm -v <mark>container_name</mark>
</li></ol>
</code></pre>
<h2>Conclusion</h2>
<p>This guide covers some of the common commands used to remove images, containers, and volumes with Docker. There are many other combinations and flags that can be used with each. For a comprehensive guide to whatâs available, see the Docker documentation for <a href="https://docs.docker.com/engine/reference/commandline/system_prune/"><code>docker system prune</code></a>, <a href="https://docs.docker.com/engine/reference/commandline/rmi/"><code>docker rmi</code></a>, <a href="https://docs.docker.com/engine/reference/commandline/rm/"><code>docker rm</code></a>, and <a href="https://docs.docker.com/engine/reference/commandline/volume_rm/"><code>docker volume rm</code></a>. If there are common cleanup tasks youâd like to see in the guide, please ask or make suggestions in the comments.</p>
<p>For a detailed look at the different components of a Docker container, check out <a href="https://www.digitalocean.com/community/tutorials/the-docker-ecosystem-an-introduction-to-common-components">The Docker Ecosystem: An Introduction to Common Components</a>.</p>
</div>||||I|||| Web hosting without headaches. Try Cloudways with $100 in free credit! Sign up ->
 * We're hiring
 * Blog
 * Docs
 * Get Support
 * Sales
 * Products

 Featured Products

 + Droplets Scalable virtual machines
 + Kubernetes Managed Kubernetes clusters
 + Cloudways Managed cloud hosting
 + App Platform Get apps to market faster
 + Databases Worry-free setup & maintenance
 + Spaces Simple object storage

 Compute

 + Droplets
 + Kubernetes
 + App Platform
 + Functions

 Cloud Website Hosting

 + Cloudways

 Storage

 + Spaces Object Storage
 + Volumes Block Storage

 Networking

 + Virtual Private Cloud (VPC)
 + Cloud Firewalls
 + Load Balancers
 + DNS

 Managed Databases

 + MongoDB
 + MySQL
 + PostgreSQL
 + Redisâ¢

 Developer Tools

 + API
 + CLI
 + Support Plans
 + Monitoring
 + Uptime
 See all products
 * Solutions

 Our Business Solutions

 + Website Hosting Simple and reliable cloud website hosting
 + VPS Hosting VPS hosting options suited to every need

 Cloudways

 + Managed WordPress
 + Managed Woocommerce
 + Managed Magento

 By use case

 + Cloud VPN
 + Web & Mobile Apps
 + Game Development
 + Video Streaming
 + SaaS Platforms
 + Blockchain

 Resources

 + Customers
 + Security
 + Startup Resources
 + Questions?
 Speak With An Expert Today
 See all solutions
 * Marketplace
 * Community

 Our community

 + Developer Center Learn, build, and scale.
 + Community Home DevOps and development guides
 + CSS-Tricks All things web design

 Resources

 + Tutorials
 + Questions And Answers
 + Tools
 + Write for DOnations
 + Customer Stories
 + DigitalOcean Blog

 Get Involved

 + Hatch Startup Program
 + Open Source Sponsorships
 + Hacktoberfest
 + Deploy
 + DO Impact

 Documentation

 + Quick Start
 + Droplets
 + Storage
 + App Platform
 + API Reference
 + Domains and DNS
 * Pricing
 * Log in
 + Sign in
 CommunityDigitalOcean
 * Sign up
 + Sign up
 CommunityDigitalOcean
 * We're hiring
 * Blog
 * Docs
 * Get Support
 * Sales
 * Tutorials
 * Questions
 * Learning Paths
 * For Businesses
 * Product Docs
 * Social Impact
 * Search Community
 CONTENTS
 * Purging All Unused or Dangling Images, Containers, Volumes, and Networks
 * Removing Docker Images
 * Removing Containers
 * Removing Volumes
 * Conclusion

 Related

 How To Install Docker On Ubuntu 13.04 x64 VPS
 View
 How To Install and Use Docker: Getting Started
 View

 // Tutorial //

 How To Remove Docker Images, Containers, and Volumes

 Published on November 17, 2016 Â· Updated on November 22, 2021
 * Docker
 * DigitalOcean App Platform
 By Melissa Anderson
 Developer and author at DigitalOcean.
 English

 Introduction

 Docker makes it easy to wrap your applications and services in containers so you can run them anywhere. As you work with Docker, however, itâs also easy to accumulate an excessive number of unused images, containers, and data volumes that clutter the output and consume disk space.

 Docker gives you all the tools you need to clean up your system from the command line. This cheat sheet-style guide provides a quick reference to commands that are useful for freeing disk space and keeping your system organized by removing unused Docker images, containers, and volumes.

 How to Use This Guide:

 * This guide is in cheat sheet format with self-contained command-line snippets.
 * Jump to any section that is relevant to the task you are trying to complete.

 Note: The command substitution syntax, command $(command), used in the commands is available in many popular shells, such as bash, zsh, and Windows Powershell.

 Purging All Unused or Dangling Images, Containers, Volumes, and Networks

 Docker provides a single command that will clean up any resources â images, containers, volumes, and networks â that are dangling (not tagged or associated with a container):

 1. docker system prune
 
 
 

 To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command:

 1. docker system prune -a
 
 
 

 Removing Docker Images

 Remove one or more specific images

 Use the docker images command with the -a flag to locate the ID of the images you want to remove. This will show you every image, including intermediate image layers. When youâve located the images you want to delete, you can pass their ID or tag to docker rmi:

 List:

 1. docker images -a
 
 
 

 Remove:

 1. docker rmi Image Image
 
 
 

 Remove dangling images

 Docker images consist of multiple layers. Dangling images are layers that have no relationship to any tagged images. They no longer serve a purpose and consume disk space. They can be located by adding the filter flag -f with a value of dangling=true to the docker images command. When youâre sure you want to delete them, you can use the docker image prune command:

 Note: If you build an image without tagging it, the image will appear on the list of dangling images because it has no association with a tagged image. You can avoid this situation by providing a tag when you build, and you can retroactively tag an image with the docker tag command.

 List:

 1. docker images -f dangling=true
 
 
 

 Remove:

 1. docker image prune
 
 
 

 Removing images according to a pattern

 You can find all the images that match a pattern using a combination of docker images and grep. Once youâre satisfied, you can delete them by using awk to pass the IDs to docker rmi. Note that these utilities are not supplied by Docker and are not necessarily available on all systems:

 List:

 1. docker images -a | grep "pattern"
 
 
 

 Remove:

 1. docker images -a | grep "pattern" | awk '{print $3}' | xargs docker rmi
 
 
 

 Remove all images

 All the Docker images on a system can be listed by adding -a to the docker images command. Once youâre sure you want to delete them all, you can add the -q flag to pass the image ID to docker rmi:

 List:

 1. docker images -a
 
 
 

 Remove:

 1. docker rmi $(docker images -a -q)
 
 
 

 Removing Containers

 Remove one or more specific containers

 Use the docker ps command with the -a flag to locate the name or ID of the containers you want to remove:

 List:

 1. docker ps -a
 
 
 

 Remove:

 1. docker rm ID_or_Name ID_or_Name
 
 
 

 Remove a container upon exiting

 If you know when youâre creating a container that you wonât want to keep it around once youâre done, you can run docker run --rm to automatically delete it when it exits:

 Run and Remove:

 1. docker run --rm image_name
 
 
 

 Remove all exited containers

 You can locate containers using docker ps -a and filter them by their status: created, restarting, running, paused, or exited. To review the list of exited containers, use the -f flag to filter based on status. When youâve verified you want to remove those containers, use -q to pass the IDs to the docker rm command:

 List:

 1. docker ps -a -f status=exited
 
 
 

 Remove:

 1. docker rm $(docker ps -a -f status=exited -q)
 
 
 

 Remove containers using more than one filter

 Docker filters can be combined by repeating the filter flag with an additional value. This results in a list of containers that meet either condition. For example, if you want to delete all containers marked as either created (a state which can result when you run a container with an invalid command) or exited, you can use two filters:

 List:

 1. docker ps -a -f status=exited -f status=created
 
 
 

 Remove:

 1. docker rm $(docker ps -a -f status=exited -f status=created -q)
 
 
 

 Remove containers according to a pattern

 You can find all the containers that match a pattern using a combination of docker ps and grep. When youâre satisfied that you have the list you want to delete, you can use awk and xargs to supply the ID to docker rm. Note that these utilities are not supplied by Docker and are not necessarily available on all systems:

 List:

 1. docker ps -a | grep "patternâ
 
 
 

 Remove:

 1. docker ps -a | grep "pattern" | awk '{print $1}' | xargs docker rm
 
 
 

 Stop and remove all containers

 You can review the containers on your system with docker ps. Adding the -a flag will show all containers. When youâre sure you want to delete them, you can add the -q flag to supply the IDs to the docker stop and docker rm commands:

 List:

 1. docker ps -a
 
 
 

 Remove:

 1. docker stop $(docker ps -a -q)
 
 2. docker rm $(docker ps -a -q)
 
 
 

 Removing Volumes

 Remove one or more specific volumes - Docker 1.9 and later

 Use the docker volume ls command to locate the volume name or names you wish to delete. Then you can remove one or more volumes with the docker volume rm command:

 List:

 1. docker volume ls
 
 
 

 Remove:

 1. docker volume rm volume_name volume_name
 
 
 

 Remove dangling volumes - Docker 1.9 and later

 Since the point of volumes is to exist independent from containers, when a container is removed, a volume is not automatically removed at the same time. When a volume exists and is no longer connected to any containers, itâs called a dangling volume. To locate them to confirm you want to remove them, you can use the docker volume ls command with a filter to limit the results to dangling volumes. When youâre satisfied with the list, you can remove them all with docker volume prune:

 List:

 1. docker volume ls -f dangling=true
 
 
 

 Remove:

 1. docker volume prune
 
 
 

 Remove a container and its volume

 If you created an unnamed volume, it can be deleted at the same time as the container with the -v flag. Note that this only works with unnamed volumes. When the container is successfully removed, its ID is displayed. Note that no reference is made to the removal of the volume. If it is unnamed, it is silently removed from the system. If it is named, it silently stays present.

 Remove:

 1. docker rm -v container_name
 
 
 

 Conclusion

 This guide covers some of the common commands used to remove images, containers, and volumes with Docker. There are many other combinations and flags that can be used with each. For a comprehensive guide to whatâs available, see the Docker documentation for docker system prune, docker rmi, docker rm, and docker volume rm. If there are common cleanup tasks youâd like to see in the guide, please ask or make suggestions in the comments.

 For a detailed look at the different components of a Docker container, check out The Docker Ecosystem: An Introduction to Common Components.

 Spin up a virtual machine with Docker pre-configured and attached in one simple click with DigitalOcean. Let us spin up a Docker droplet for you in seconds, so you can focus on building a great application.

 Learn more here

 About the authors
 Melissa Anderson

 author

 Developer and author at DigitalOcean.

 Still looking for an answer?

 Ask a questionSearch for more help
 Was this helpful?
 YesNo
 Â
 Comments
 10 Comments
 Leave a comment...
 ï»¿

 This textbox defaults to using Markdown to format your answer.

 You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

 Sign In or Sign Up to Comment
 Tehnicaorg â¢ January 17, 2018

 Thanks for the document. To remove dangling images the command seems to be docker image prune, not docker images purge

 Î» docker image prune
 WARNING! This will remove all dangling images.
 Are you sure you want to continue? [y/N] y
 Deleted Images:
 [...]
 
 * Reply
 lucasbmd â¢ February 17, 2017

 Super handy article!

 I think the âRemoving images according to a patternâ and âRemove containers according to a patternâ are mixed up.

 For images:

 docker images | grep "pattern" | awk '{print $3}' | xargs docker rmi
 

 and alternatively, I found this one to work better (as multiple tags can link to a same image):

 docker images | grep "pattern" | awk '{print $1":"$2}' | xargs docker rmi
 

 For containers:

 docker ps -a | grep "pattern" | awk '{print $1}' | xargs docker rm
 
 * Reply
 Kyoung-Rok Jang â¢ November 20, 2016

 Great article. Thanks!

 * Reply
 piotrekrogowski â¢ January 23, 2017

 There is -q missing in Remove containers using more than one filter

 should be docker rm $(docker ps -a -f status=exited -f status=created -q)

 * Reply
 arangogutierrez â¢ October 16, 2017

 What about the build in CLI tools

 docker system prune
 
 docker volume prune
 
 docker network prune
 

 And you are done!

 * Reply
 cjratliff â¢ October 6, 2017

 This was a life saver. I am a rookie at this and it helped greatly. Thanks!

 * Reply
 BHa â¢ July 12, 2017

 Thanks for this detailed useful article! For now as a punch line you can add the new alternate way : docker system prune See https://docs.docker.com/engine/reference/commandline/system_prune/ Canât figure out since this new command released.

 * Reply
 Bron Bravo â¢ June 25, 2022

 Does anyone even use this product anymore?

 * Reply
 rivernews â¢ July 18, 2019

 Great article! Seems like it needs some update for recent version of docker (as comments below have also pointed out), but itâs a good point to start.

 * Reply
 yuliiaajs â¢ February 22, 2019

 Thanks! It resolved my issue!

 * Reply
 Load More Comments
 This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.

 Popular Topics

 * Ubuntu
 * Linux Basics
 * JavaScript
 * React
 * Python
 * Security
 * MySQL
 * Docker
 * Kubernetes
 * Browse all topic tags
 * Free Managed Hosting
 * All tutorials

 Questions

 * Q&A Forum
 * Ask a question
 * DigitalOcean Support

 Try DigitalOcean for free

 Click here to Sign up and get $200 of credit to try our products over 60 days!

 Thank you! Please check your email for further details.
 Get our biweekly newsletter

 Sign up for Infrastructure as a Newsletter.

 Hollie's Hub for Good

 Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

 Become a contributor

 You get paid; we donate to tech nonprofits.

 Featured on Community Intro to KubernetesLearn Python 3Machine Learning in PythonGetting started with Go DigitalOcean Products Virtual MachinesManaged DatabasesManaged KubernetesBlock StorageObject StorageMarketplaceVPCLoad Balancers

 Welcome to the developer cloud

 DigitalOcean makes it simple to launch in the cloud and scale up as you grow â whether youâre running one virtual machine or ten thousand.

 Learn More

 Company

 * About
 * Leadership
 * Blog
 * Careers
 * Customers
 * Partners
 * Channel Partners
 * Referral Program
 * Affiliate Program
 * Press
 * Legal
 * Security
 * Investor Relations
 * DO Impact

 Products

 * Products Overview
 * Droplets
 * Kubernetes
 * App Platform
 * Functions
 * Cloudways
 * Managed Databases
 * Spaces
 * Marketplace
 * Load Balancers
 * Block Storage
 * Tools & Integrations
 * API
 * Pricing
 * Documentation
 * Release Notes
 * Uptime

 Community

 * Tutorials
 * Q&A
 * CSS-Tricks
 * Write for DOnations
 * Currents Research
 * Hatch Startup Program
 * deploy by DigitalOcean
 * Shop Swag
 * Research Program
 * Open Source
 * Code of Conduct
 * Newsletter Signup
 * Meetups

 Solutions

 * Website Hosting
 * VPS Hosting
 * Web & Mobile Apps
 * Game Development
 * Streaming
 * VPN
 * SaaS Platforms
 * Cloud Hosting for Blockchain
 * Startup Resources

 Contact

 * Support
 * Sales
 * Report Abuse
 * System Status
 * Share your ideas

 Company

 * About
 * Leadership
 * Blog
 * Careers
 * Customers
 * Partners
 * Channel Partners
 * Referral Program
 * Affiliate Program
 * Press
 * Legal
 * Security
 * Investor Relations
 * DO Impact

 Products

 * Products Overview
 * Droplets
 * Kubernetes
 * App Platform
 * Functions
 * Cloudways
 * Managed Databases
 * Spaces
 * Marketplace
 * Load Balancers
 * Block Storage
 * Tools & Integrations
 * API
 * Pricing
 * Documentation
 * Release Notes
 * Uptime

 Community

 * Tutorials
 * Q&A
 * CSS-Tricks
 * Write for DOnations
 * Currents Research
 * Hatch Startup Program
 * deploy by DigitalOcean
 * Shop Swag
 * Research Program
 * Open Source
 * Code of Conduct
 * Newsletter Signup
 * Meetups

 Solutions

 * Website Hosting
 * VPS Hosting
 * Web & Mobile Apps
 * Game Development
 * Streaming
 * VPN
 * SaaS Platforms
 * Cloud Hosting for Blockchain
 * Startup Resources

 Contact

 * Support
 * Sales
 * Report Abuse
 * System Status
 * Share your ideas

 Â© 2023 DigitalOcean, LLC. All rights reserved.

 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
Introduction
 Docker makes it easy to wrap your applications and services in containers so you can run them anywhere. As you work with Docker, however, itâs also easy to accumulate an excessive number of unused images, containers, and data volumes that clutter the output and consume disk space.
Docker gives you all the tools you need to clean up your system from the command line. This cheat sheet-style guide provides a quick reference to commands that are useful for freeing disk space and keeping your system organized by removing unused Docker images, containers, and volumes.
 How to Use This Guide: 
This guide is in cheat sheet format with self-contained command-line snippets.
Jump to any section that is relevant to the task you are trying to complete.
 Note: The command substitution syntax,  command $(command), used in the commands is available in many popular shells, such as bash, zsh, and Windows Powershell.
Purging All Unused or Dangling Images, Containers, Volumes, and Networks
Docker provides a single command that will clean up any resources â images, containers, volumes, and networks â that are dangling (not tagged or associated with a container):
   docker system prune
 
 
To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command:
   docker system prune -a
 
 
Removing Docker Images
Remove one or more specific images
Use the docker images command with the -a flag to locate the ID of the images you want to remove. This will show you every image, including intermediate image layers. When youâve located the images you want to delete, you can pass their ID or tag to docker rmi:
 List: 
   docker images -a
 
 
 Remove: 
   docker rmi Image Image
 
 
Remove dangling images
Docker images consist of multiple layers. Dangling images are layers that have no relationship to any tagged images. They no longer serve a purpose and consume disk space. They can be located by adding the filter flag -f with a value of dangling=true to the docker images command. When youâre sure you want to delete them, you can use the docker image prune command:
 Note: If you build an image without tagging it, the image will appear on the list of dangling images because it has no association with a tagged image. You can avoid this situation by providing a tag when you build, and you can retroactively tag an image with the  docker tag  command.
 List: 
   docker images -f dangling=true
 
 
 Remove: 
   docker image prune
 
 
Removing images according to a pattern
You can find all the images that match a pattern using a combination of docker images and  grep . Once youâre satisfied, you can delete them by using  awk  to pass the IDs to docker rmi. Note that these utilities are not supplied by Docker and are not necessarily available on all systems:
 List: 
   docker images -a | grep "pattern"
 
 
 Remove: 
   docker images -a | grep "pattern" | awk '{print $3}' | xargs docker rmi
 
 
Remove all images
All the Docker images on a system can be listed by adding -a to the docker images command. Once youâre sure you want to delete them all, you can add the -q flag to pass the image ID to docker rmi:
 List: 
   docker images -a
 
 
 Remove: 
   docker rmi $(docker images -a -q)
 
 
Removing Containers
Remove one or more specific containers
Use the docker ps command with the -a flag to locate the name or ID of the containers you want to remove:
 List: 
   docker ps -a
 
 
 Remove: 
   docker rm ID_or_Name ID_or_Name
 
 
Remove a container upon exiting
If you know when youâre creating a container that you wonât want to keep it around once youâre done, you can run docker run --rm to automatically delete it when it exits:
 Run and Remove: 
   docker run --rm image_name
 
 
Remove all exited containers
You can locate containers using docker ps -a and filter them by their status: created, restarting, running, paused, or exited. To review the list of exited containers, use the -f flag to filter based on status. When youâve verified you want to remove those containers, use -q to pass the IDs to the docker rm command:
 List: 
   docker ps -a -f status=exited
 
 
 Remove: 
   docker rm $(docker ps -a -f status=exited -q)
 
 
Remove containers using more than one filter
Docker filters can be combined by repeating the filter flag with an additional value. This results in a list of containers that meet either condition. For example, if you want to delete all containers marked as either created (a state which can result when you run a container with an invalid command) or exited, you can use two filters:
 List: 
   docker ps -a -f status=exited -f status=created
 
 
 Remove: 
   docker rm $(docker ps -a -f status=exited -f status=created -q)
 
 
Remove containers according to a pattern
You can find all the containers that match a pattern using a combination of docker ps and  grep . When youâre satisfied that you have the list you want to delete, you can use  awk  and xargs to supply the ID to docker rm. Note that these utilities are not supplied by Docker and are not necessarily available on all systems:
 List: 
   docker ps -a | grep "patternâ
 
 
 Remove: 
   docker ps -a | grep "pattern" | awk '{print $1}' | xargs docker rm
 
 
Stop and remove all containers
You can review the containers on your system with docker ps. Adding the -a flag will show all containers. When youâre sure you want to delete them, you can add the -q flag to supply the IDs to the docker stop and docker rm commands:
 List: 
   docker ps -a
 
 
 Remove: 
   docker stop $(docker ps -a -q)
 docker rm $(docker ps -a -q)
 
 
Removing Volumes
Remove one or more specific volumes - Docker 1.9 and later
Use the docker volume ls command to locate the volume name or names you wish to delete. Then you can remove one or more volumes with the docker volume rm command:
 List: 
   docker volume ls
 
 
 Remove: 
   docker volume rm volume_name volume_name
 
 
Remove dangling volumes - Docker 1.9 and later
Since the point of volumes is to exist independent from containers, when a container is removed, a volume is not automatically removed at the same time. When a volume exists and is no longer connected to any containers, itâs called a dangling volume. To locate them to confirm you want to remove them, you can use the docker volume ls command with a filter to limit the results to dangling volumes. When youâre satisfied with the list, you can remove them all with docker volume prune:
 List: 
   docker volume ls -f dangling=true
 
 
 Remove: 
   docker volume prune
 
 
Remove a container and its volume
If you created an unnamed volume, it can be deleted at the same time as the container with the -v flag. Note that this only works with unnamed volumes. When the container is successfully removed, its ID is displayed. Note that no reference is made to the removal of the volume. If it is unnamed, it is silently removed from the system. If it is named, it silently stays present.
 Remove: 
   docker rm -v container_name
 
 
Conclusion
This guide covers some of the common commands used to remove images, containers, and volumes with Docker. There are many other combinations and flags that can be used with each. For a comprehensive guide to whatâs available, see the Docker documentation for  docker system prune ,  docker rmi ,  docker rm , and  docker volume rm . If there are common cleanup tasks youâd like to see in the guide, please ask or make suggestions in the comments.
For a detailed look at the different components of a Docker container, check out The Docker Ecosystem: An Introduction to Common Components.
How To Remove Docker Images, Containers, and Volumes | DigitalOcean
https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes
https://docs.docker.com/engine/reference/commandline/container_prune/
docker container prune
2023-02-06
None
<div><section>
 
<p>Remove all stopped containers</p>
<h2>Usage</h2>
<div><pre><code>$ docker container prune [OPTIONS]
</code></pre></div>
<p>Refer to the <a href="#options">options section</a> for an overview of available <a href="#options"><code>OPTIONS</code></a> for this command.</p>
<h2>Description</h2>
<p>Removes all stopped containers.</p>
<p>For example uses of this command, refer to the <a href="#examples">examples section</a> below.</p>
<h2>Options</h2>
<table>
<thead>
 <tr>
 <td>Name, shorthand</td>
 <td>Default</td>
 <td>Description</td>
 </tr>
</thead>
<tbody>
 
 
 
 
 
 
 
 <tr>
 <td><a href="#filter"><code>--filter</code></a></td>
 <td></td>
 <td>Provide filter values (e.g. <code>until=&lt;timestamp&gt;</code>)</td>
 </tr>
 
 
 
 
 
 
 
 <tr>
 <td><code>--force</code> , <code>-f</code></td>
 <td></td>
 <td>Do not prompt for confirmation</td>
 </tr>
 
 
 
 
 
 
 
 <tr>
 <td><code>--help</code></td>
 <td></td>
 <td>Print usage</td>
 </tr>
 
</tbody>
</table>
<h2>Examples</h2>
<h3>Prune containers</h3>
<div><pre><code>$ docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
4a7f7eebae0f63178aff7eb0aa39cd3f0627a203ab2df258c1a00b456cf20063
f98f9c2aa1eaf727e4ec9c0283bc7d4aa4762fbdba7f26191f26c97f64090360
Total reclaimed space: 212 B
</code></pre></div>
<h3>Filtering (--filter)</h3>
<p>The filtering flag (<code>--filter</code>) format is of âkey=valueâ. If there is more
than one filter, then pass multiple flags (e.g., <code>--filter "foo=bar" --filter "bif=baz"</code>)</p>
<p>The currently supported filters are:</p>
<ul>
 <li>until (<code>&lt;timestamp&gt;</code>) - only remove containers created before given timestamp</li>
 <li>label (<code>label=&lt;key&gt;</code>, <code>label=&lt;key&gt;=&lt;value&gt;</code>, <code>label!=&lt;key&gt;</code>, or <code>label!=&lt;key&gt;=&lt;value&gt;</code>) - only remove containers with (or without, in case <code>label!=...</code> is used) the specified labels.</li>
</ul>
<p>The <code>until</code> filter can be Unix timestamps, date formatted
timestamps, or Go duration strings (e.g. <code>10m</code>, <code>1h30m</code>) computed
relative to the daemon machineâs time. Supported formats for date
formatted time stamps include RFC3339Nano, RFC3339, <code>2006-01-02T15:04:05</code>,
<code>2006-01-02T15:04:05.999999999</code>, <code>2006-01-02Z07:00</code>, and <code>2006-01-02</code>. The local
timezone on the daemon will be used if you do not provide either a <code>Z</code> or a
<code>+-00:00</code> timezone offset at the end of the timestamp. When providing Unix
timestamps enter seconds[.nanoseconds], where seconds is the number of seconds
that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap
seconds (aka Unix epoch or Unix time), and the optional .nanoseconds field is a
fraction of a second no more than nine digits long.</p>
<p>The <code>label</code> filter accepts two formats. One is the <code>label=...</code> (<code>label=&lt;key&gt;</code> or <code>label=&lt;key&gt;=&lt;value&gt;</code>),
which removes containers with the specified labels. The other
format is the <code>label!=...</code> (<code>label!=&lt;key&gt;</code> or <code>label!=&lt;key&gt;=&lt;value&gt;</code>), which removes
containers without the specified labels.</p>
<p>The following removes containers created more than 5 minutes ago:</p>
<div><pre><code>$ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
CONTAINER ID IMAGE COMMAND CREATED AT STATUS
61b9efa71024 busybox "sh" 2017-01-04 13:23:33 -0800 PST Exited (0) 41 seconds ago
53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 12 minutes ago
$ docker container prune --force --filter "until=5m"
Deleted Containers:
53a9bc23a5168b6caa2bfbefddf1b30f93c7ad57f3dec271fd32707497cb9369
Total reclaimed space: 25 B
$ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
CONTAINER ID IMAGE COMMAND CREATED AT STATUS
61b9efa71024 busybox "sh" 2017-01-04 13:23:33 -0800 PST Exited (0) 44 seconds ago
</code></pre></div>
<p>The following removes containers created before <code>2017-01-04T13:10:00</code>:</p>
<div><pre><code>$ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
CONTAINER ID IMAGE COMMAND CREATED AT STATUS
53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 7 minutes ago
4a75091a6d61 busybox "sh" 2017-01-04 13:09:53 -0800 PST Exited (0) 9 minutes ago
$ docker container prune --force --filter "until=2017-01-04T13:10:00"
Deleted Containers:
4a75091a6d618526fcd8b33ccd6e5928ca2a64415466f768a6180004b0c72c6c
Total reclaimed space: 27 B
$ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
CONTAINER ID IMAGE COMMAND CREATED AT STATUS
53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 9 minutes ago
</code></pre></div>
<h2>Parent command</h2>
<table>
 <thead>
 <tr>
 <th>Command</th>
 <th>Description</th>
 </tr>
 </thead>
 <tbody>
 <tr>
 <td><a href="/engine/reference/commandline/container/">docker container</a></td>
 <td>Manage containers</td>
 </tr>
 </tbody>
</table>
<table>
<thead>
 <tr>
 <td>Command</td>
 <td>Description</td>
 </tr>
</thead>
<tbody>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_attach/">docker container attach</a></td>
 <td>Attach local standard input, output, and error streams to a running container
</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_commit/">docker container commit</a></td>
 <td>Create a new image from a containerâs changes</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_cp/">docker container cp</a></td>
 <td>Copy files/folders between a container and the local filesystem</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_create/">docker container create</a></td>
 <td>Create a new container</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_diff/">docker container diff</a></td>
 <td>Inspect changes to files or directories on a containerâs filesystem</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_exec/">docker container exec</a></td>
 <td>Execute a command in a running container</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_export/">docker container export</a></td>
 <td>Export a containerâs filesystem as a tar archive</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_inspect/">docker container inspect</a></td>
 <td>Display detailed information on one or more containers</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_kill/">docker container kill</a></td>
 <td>Kill one or more running containers</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_logs/">docker container logs</a></td>
 <td>Fetch the logs of a container</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_ls/">docker container ls</a></td>
 <td>List containers</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_pause/">docker container pause</a></td>
 <td>Pause all processes within one or more containers</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_port/">docker container port</a></td>
 <td>List port mappings or a specific mapping for the container</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_prune/">docker container prune</a></td>
 <td>Remove all stopped containers</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_rename/">docker container rename</a></td>
 <td>Rename a container</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_restart/">docker container restart</a></td>
 <td>Restart one or more containers</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_rm/">docker container rm</a></td>
 <td>Remove one or more containers</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_run/">docker container run</a></td>
 <td>Create and run a new container from an image</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_start/">docker container start</a></td>
 <td>Start one or more stopped containers</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_stats/">docker container stats</a></td>
 <td>Display a live stream of container(s) resource usage statistics</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_stop/">docker container stop</a></td>
 <td>Stop one or more running containers</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_top/">docker container top</a></td>
 <td>Display the running processes of a container</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_unpause/">docker container unpause</a></td>
 <td>Unpause all processes within one or more containers</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_update/">docker container update</a></td>
 <td>Update configuration of one or more containers</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/container_wait/">docker container wait</a></td>
 <td>Block until one or more containers stop, then print their exit codes</td>
 </tr>
</tbody>
</table>
 </section>||||I|||| Search
 Toggle navigation
 * Home
 * Guides
 * Manuals
 * Reference
 * Samples
 * Contribute
 1. 
 2. Reference
 3. Command-line reference
 4. Docker CLI (docker)
 5. docker container
 6. docker container prune

 docker container prune


 Remove all stopped containers

 Usage

 $ docker container prune [OPTIONS]
 

 Refer to the options section for an overview of available OPTIONS for this command.

 Description

 Removes all stopped containers.

 For example uses of this command, refer to the examples section below.

 Options

 Name, shorthand Default Description 
 --filter Provide filter values (e.g. until=<timestamp>)
 --force , -f Do not prompt for confirmation 
 --help Print usage 
 

 Examples

 Prune containers

 $ docker container prune
 WARNING! This will remove all stopped containers.
 Are you sure you want to continue? [y/N] y
 Deleted Containers:
 4a7f7eebae0f63178aff7eb0aa39cd3f0627a203ab2df258c1a00b456cf20063
 f98f9c2aa1eaf727e4ec9c0283bc7d4aa4762fbdba7f26191f26c97f64090360
 
 Total reclaimed space: 212 B
 

 Filtering (--filter)

 The filtering flag (--filter) format is of âkey=valueâ. If there is more than one filter, then pass multiple flags (e.g., --filter "foo=bar" --filter "bif=baz")

 The currently supported filters are:

 * until (<timestamp>) - only remove containers created before given timestamp
 * label (label=<key>, label=<key>=<value>, label!=<key>, or label!=<key>=<value>) - only remove containers with (or without, in case label!=... is used) the specified labels.

 The until filter can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. 10m, 1h30m) computed relative to the daemon machineâs time. Supported formats for date formatted time stamps include RFC3339Nano, RFC3339, 2006-01-02T15:04:05, 2006-01-02T15:04:05.999999999, 2006-01-02Z07:00, and 2006-01-02. The local timezone on the daemon will be used if you do not provide either a Z or a +-00:00 timezone offset at the end of the timestamp. When providing Unix timestamps enter seconds[.nanoseconds], where seconds is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (aka Unix epoch or Unix time), and the optional .nanoseconds field is a fraction of a second no more than nine digits long.

 The label filter accepts two formats. One is the label=... (label=<key> or label=<key>=<value>), which removes containers with the specified labels. The other format is the label!=... (label!=<key> or label!=<key>=<value>), which removes containers without the specified labels.

 The following removes containers created more than 5 minutes ago:

 $ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
 
 CONTAINER ID IMAGE COMMAND CREATED AT STATUS
 61b9efa71024 busybox "sh" 2017-01-04 13:23:33 -0800 PST Exited (0) 41 seconds ago
 53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 12 minutes ago
 
 $ docker container prune --force --filter "until=5m"
 
 Deleted Containers:
 53a9bc23a5168b6caa2bfbefddf1b30f93c7ad57f3dec271fd32707497cb9369
 
 Total reclaimed space: 25 B
 
 $ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
 
 CONTAINER ID IMAGE COMMAND CREATED AT STATUS
 61b9efa71024 busybox "sh" 2017-01-04 13:23:33 -0800 PST Exited (0) 44 seconds ago
 

 The following removes containers created before 2017-01-04T13:10:00:

 $ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
 
 CONTAINER ID IMAGE COMMAND CREATED AT STATUS
 53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 7 minutes ago
 4a75091a6d61 busybox "sh" 2017-01-04 13:09:53 -0800 PST Exited (0) 9 minutes ago
 
 $ docker container prune --force --filter "until=2017-01-04T13:10:00"
 
 Deleted Containers:
 4a75091a6d618526fcd8b33ccd6e5928ca2a64415466f768a6180004b0c72c6c
 
 Total reclaimed space: 27 B
 
 $ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
 
 CONTAINER ID IMAGE COMMAND CREATED AT STATUS
 53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 9 minutes ago
 

 Parent command

 Command Description 
 docker container Manage containers
 

 Related commands

 Command Description  
 docker container attach Attach local standard input, output, and error streams to a running container
 docker container commit Create a new image from a containerâs changes 
 docker container cp Copy files/folders between a container and the local filesystem 
 docker container create Create a new container 
 docker container diff Inspect changes to files or directories on a containerâs filesystem 
 docker container exec Execute a command in a running container 
 docker container export Export a containerâs filesystem as a tar archive 
 docker container inspect Display detailed information on one or more containers 
 docker container kill Kill one or more running containers 
 docker container logs Fetch the logs of a container 
 docker container ls List containers 
 docker container pause Pause all processes within one or more containers 
 docker container port List port mappings or a specific mapping for the container 
 docker container prune Remove all stopped containers 
 docker container rename Rename a container 
 docker container restart Restart one or more containers 
 docker container rm Remove one or more containers 
 docker container run Create and run a new container from an image 
 docker container start Start one or more stopped containers 
 docker container stats Display a live stream of container(s) resource usage statistics 
 docker container stop Stop one or more running containers 
 docker container top Display the running processes of a container 
 docker container unpause Unpause all processes within one or more containers 
 docker container update Update configuration of one or more containers 
 docker container wait Block until one or more containers stop, then print their exit codes 
 
 * 
 Contents:
 ×
 Page details
 * Edit this page
 * Request changes
 Contents
 * Usage
 * Description
 * Options
 * Examples
 + Prune containers
 + Filtering (--filter)
 * Parent command
 * Related commands
 * Product offerings
 * Docker Personal
 * Docker Pro
 * Docker Team
 * Docker Business
 * Compare Subscriptions
 * Features
 * Docker Desktop
 * Docker Hub
 * Secure Software Supply Chain
 * Container Runtime
 * Developer Tools
 * Trusted Content
 * Docker Product Roadmap
 * Developers
 * Use Cases
 * Get Started
 * Blog
 * Community
 * Open Source
 * Preview Program
 * Pricing
 * FAQ
 * Docker Verified Publisher
 * Partners
 * About Us
 * What is a Container?
 * Why Docker?
 * Virtual Events
 * Swag Store
 * Newsroom
 * Careers
 * Contact Us
 * Customers
 * Newsletter
 * Terms of Service
 * Status
 * Legal

 Copyright © 2013-2023 Docker Inc. All rights reserved.

 Cookie Settings
 * Twitter
 * Youtube
 * GitHub
 * Linkedin
 * Facebook
 * Slideshare
 * Reddit
Remove all stopped containers
Usage
  $ docker container prune [OPTIONS]
  
Refer to the options section for an overview of available  OPTIONS  for this command.
Description
Removes all stopped containers.
For example uses of this command, refer to the examples section below.
Options
 
 Name, shorthand
 Default
 Description
 
 
 
 
 
 
 
 
 
   --filter  
  
 Provide filter values (e.g. until=&lt;timestamp&gt;)
 
 
 
 
 
 
 
 
 
  --force , -f 
  
 Do not prompt for confirmation
 
 
 
 
 
 
 
 
 
  --help 
  
 Print usage
 
 
Examples
Prune containers
  $ docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
4a7f7eebae0f63178aff7eb0aa39cd3f0627a203ab2df258c1a00b456cf20063
f98f9c2aa1eaf727e4ec9c0283bc7d4aa4762fbdba7f26191f26c97f64090360
Total reclaimed space: 212 B
  
Filtering (--filter)
The filtering flag (--filter) format is of âkey=valueâ. If there is more
than one filter, then pass multiple flags (e.g., --filter "foo=bar" --filter "bif=baz")
The currently supported filters are:
 until (&lt;timestamp&gt;) - only remove containers created before given timestamp
 label (label=&lt;key&gt;, label=&lt;key&gt;=&lt;value&gt;, label!=&lt;key&gt;, or label!=&lt;key&gt;=&lt;value&gt;) - only remove containers with (or without, in case label!=... is used) the specified labels.
The until filter can be Unix timestamps, date formatted
timestamps, or Go duration strings (e.g. 10m, 1h30m) computed
relative to the daemon machineâs time. Supported formats for date
formatted time stamps include RFC3339Nano, RFC3339, 2006-01-02T15:04:05,
2006-01-02T15:04:05.999999999, 2006-01-02Z07:00, and 2006-01-02. The local
timezone on the daemon will be used if you do not provide either a Z or a
+-00:00 timezone offset at the end of the timestamp. When providing Unix
timestamps enter seconds[.nanoseconds], where seconds is the number of seconds
that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap
seconds (aka Unix epoch or Unix time), and the optional .nanoseconds field is a
fraction of a second no more than nine digits long.
The label filter accepts two formats. One is the label=... (label=&lt;key&gt; or label=&lt;key&gt;=&lt;value&gt;),
which removes containers with the specified labels. The other
format is the label!=... (label!=&lt;key&gt; or label!=&lt;key&gt;=&lt;value&gt;), which removes
containers without the specified labels.
The following removes containers created more than 5 minutes ago:
  $ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
CONTAINER ID IMAGE COMMAND CREATED AT STATUS
61b9efa71024 busybox "sh" 2017-01-04 13:23:33 -0800 PST Exited (0) 41 seconds ago
53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 12 minutes ago
$ docker container prune --force --filter "until=5m"
Deleted Containers:
53a9bc23a5168b6caa2bfbefddf1b30f93c7ad57f3dec271fd32707497cb9369
Total reclaimed space: 25 B
$ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
CONTAINER ID IMAGE COMMAND CREATED AT STATUS
61b9efa71024 busybox "sh" 2017-01-04 13:23:33 -0800 PST Exited (0) 44 seconds ago
  
The following removes containers created before 2017-01-04T13:10:00:
  $ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
CONTAINER ID IMAGE COMMAND CREATED AT STATUS
53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 7 minutes ago
4a75091a6d61 busybox "sh" 2017-01-04 13:09:53 -0800 PST Exited (0) 9 minutes ago
$ docker container prune --force --filter "until=2017-01-04T13:10:00"
Deleted Containers:
4a75091a6d618526fcd8b33ccd6e5928ca2a64415466f768a6180004b0c72c6c
Total reclaimed space: 27 B
$ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
CONTAINER ID IMAGE COMMAND CREATED AT STATUS
53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 9 minutes ago
  
Parent command
 
 
 Command
 Description
 
 
 
 
  docker container 
 Manage containers
 
 
 
 Command
 Description
 
 
 
  docker container attach 
 Attach local standard input, output, and error streams to a running container
 
 
 
  docker container commit 
 Create a new image from a containerâs changes
 
 
 
  docker container cp 
 Copy files/folders between a container and the local filesystem
 
 
 
  docker container create 
 Create a new container
 
 
 
  docker container diff 
 Inspect changes to files or directories on a containerâs filesystem
 
 
 
  docker container exec 
 Execute a command in a running container
 
 
 
  docker container export 
 Export a containerâs filesystem as a tar archive
 
 
 
  docker container inspect 
 Display detailed information on one or more containers
 
 
 
  docker container kill 
 Kill one or more running containers
 
 
 
  docker container logs 
 Fetch the logs of a container
 
 
 
  docker container ls 
 List containers
 
 
 
  docker container pause 
 Pause all processes within one or more containers
 
 
 
  docker container port 
 List port mappings or a specific mapping for the container
 
 
 
  docker container prune 
 Remove all stopped containers
 
 
 
  docker container rename 
 Rename a container
 
 
 
  docker container restart 
 Restart one or more containers
 
 
 
  docker container rm 
 Remove one or more containers
 
 
 
  docker container run 
 Create and run a new container from an image
 
 
 
  docker container start 
 Start one or more stopped containers
 
 
 
  docker container stats 
 Display a live stream of container(s) resource usage statistics
 
 
 
  docker container stop 
 Stop one or more running containers
 
 
 
  docker container top 
 Display the running processes of a container
 
 
 
  docker container unpause 
 Unpause all processes within one or more containers
 
 
 
  docker container update 
 Update configuration of one or more containers
 
 
 
  docker container wait 
 Block until one or more containers stop, then print their exit codes
docker container prune
https://docs.docker.com/engine/reference/commandline/container_prune/
https://blog.akbal.dev/how-to-remove-unused-docker-resources
How to remove unused Docker resources
2020-12-16
Alejandro Akbal
<div><div>
<h2>Introduction</h2>
<p>Chances are that you've been running Docker for some time and found out that your system's storage is almost full.</p>
<p>This is completely normal as Docker bundles all the needed dependencies with each container and doesn't remove anything if you don't explicitly tell it to do so.</p>
<p>So let's learn how to prune unused and unnecessary <strong>images, containers, volumes and networks</strong>!</p>
<blockquote>
<p>This tutorial will help you liberate space on your system without breaking anything in the process.</p>
</blockquote>
<hr />
<h2>Before we start</h2>
<p>We will be using the Docker CLI, so I expect you to be a bit familiar with it.</p>
<p>Otherwise, just use <code>docker --help</code> on the terminal and toy with it a little.</p>
<h3>Requisites</h3>
<ul>
<li>A bit of Docker knowledge</li>
</ul>
<hr />
<h2>Images</h2>
<p>Remove all images that are not tagged or referenced by any container</p>
<pre><code>docker image prune
</code></pre>
<hr />
<h2>Containers</h2>
<p>Remove all stopped containers</p>
<pre><code>docker container prune
</code></pre>
<hr />
<h2>Volumes</h2>
<p>Remove all volumes not used by at least one container</p>
<pre><code>docker volume prune
</code></pre>
<hr />
<h2>Networks</h2>
<p>Remove all networks not used by at least one container</p>
<pre><code>docker network prune
</code></pre>
<hr />
<h2>Everything</h2>
<p>To finalize, lets remove everything --<em>but volumes</em>-- with a single command.</p>
<pre><code>docker system prune
</code></pre>
<p>If you want to remove volumes too, just append <code>--volumes</code> at the end.</p>
<pre><code>docker system prune --volumes
</code></pre>
<p>And if you want to remove EVERYTHING, just append <code>--all</code> at the end.</p>
<pre><code>docker system prune --all
</code></pre>
<p><strong>And voilà, that removed every single resource that was unnecessary on your system!</strong></p>
<hr />
<h2>Troubleshooting</h2>
<p>You might find that some images can't be removed because they are used. In this case you want to remove the resource that is using it, most likely a container.</p>
<hr />
<h2>End</h2>
<h3>What's next?</h3>
<p>If you want to read more, please check out the <a href="https://docs.docker.com/config/pruning/">official Docker guide to pruning</a>.</p>
<h3>Self-promotion</h3>
<p>If you have found this useful, then you should follow me, I will be posting more interesting content! 🥰</p>
<ul>
<li><a href="https://redirect.akbal.dev/github">GitHub</a></li>
<li><a href="https://redirect.akbal.dev/twitter">Twitter</a></li>
<li><a href="https://redirect.akbal.dev/dev.to">Dev.to</a></li>
</ul>
<p>Or support me financially. 💸</p>
<ul>
<li><a href="https://redirect.akbal.dev/github/sponsor">GitHub Sponsors</a></li>
<li><a href="https://redirect.akbal.dev/liberapay">LiberaPay</a></li>
<li><a href="https://redirect.akbal.dev/paypal">PayPal</a></li>
</ul>
<h3>Conclusion</h3>
<p>Today you have learned how to free up space on your system by removing Docker's unused images, containers, volumes and networks.</p>
<p><strong>Let me know how much space you have recovered in the comments!</strong></p>
</div>||||I|||| Alejandro Akbal

 Follow

 Alejandro Akbal

 Follow

 How to remove unused Docker resources

 Alejandro Akbal
 · Dec 16, 2020 ·

 2 min read

 Play this article
 Your browser does not support the audio element. SPEED 1 X

 Introduction

 Chances are that you've been running Docker for some time and found out that your system's storage is almost full.

 This is completely normal as Docker bundles all the needed dependencies with each container and doesn't remove anything if you don't explicitly tell it to do so.

 So let's learn how to prune unused and unnecessary images, containers, volumes and networks!

 This tutorial will help you liberate space on your system without breaking anything in the process.

 Before we start

 We will be using the Docker CLI, so I expect you to be a bit familiar with it.

 Otherwise, just use docker --help on the terminal and toy with it a little.

 Requisites

 * A bit of Docker knowledge

 Images

 Remove all images that are not tagged or referenced by any container

 docker image prune
 

 Containers

 Remove all stopped containers

 docker container prune
 

 Volumes

 Remove all volumes not used by at least one container

 docker volume prune
 

 Networks

 Remove all networks not used by at least one container

 docker network prune
 

 Everything

 To finalize, lets remove everything --but volumes-- with a single command.

 docker system prune
 

 If you want to remove volumes too, just append --volumes at the end.

 docker system prune --volumes
 

 And if you want to remove EVERYTHING, just append --all at the end.

 docker system prune --all
 

 And voilà, that removed every single resource that was unnecessary on your system!

 Troubleshooting

 You might find that some images can't be removed because they are used. In this case you want to remove the resource that is using it, most likely a container.

 End

 What's next?

 If you want to read more, please check out the official Docker guide to pruning.

 Self-promotion

 If you have found this useful, then you should follow me, I will be posting more interesting content! 🥰

 * GitHub
 * Twitter
 * Dev.to

 Or support me financially. 💸

 * GitHub Sponsors
 * LiberaPay
 * PayPal

 Conclusion

 Today you have learned how to free up space on your system by removing Docker's unused images, containers, volumes and networks.

 Let me know how much space you have recovered in the comments!

 Share this
Introduction
Chances are that you've been running Docker for some time and found out that your system's storage is almost full.
This is completely normal as Docker bundles all the needed dependencies with each container and doesn't remove anything if you don't explicitly tell it to do so.
So let's learn how to prune unused and unnecessary images, containers, volumes and networks!
This tutorial will help you liberate space on your system without breaking anything in the process.
Before we start
We will be using the Docker CLI, so I expect you to be a bit familiar with it.
Otherwise, just use docker --help on the terminal and toy with it a little.
Requisites
A bit of Docker knowledge
Images
Remove all images that are not tagged or referenced by any container
 docker image prune
 
Containers
Remove all stopped containers
 docker container prune
 
Volumes
Remove all volumes not used by at least one container
 docker volume prune
 
Networks
Remove all networks not used by at least one container
 docker network prune
 
Everything
To finalize, lets remove everything --but volumes-- with a single command.
 docker system prune
 
If you want to remove volumes too, just append --volumes at the end.
 docker system prune --volumes
 
And if you want to remove EVERYTHING, just append --all at the end.
 docker system prune --all
 
 And voilà, that removed every single resource that was unnecessary on your system! 
Troubleshooting
You might find that some images can't be removed because they are used. In this case you want to remove the resource that is using it, most likely a container.
End
What's next?
If you want to read more, please check out the official Docker guide to pruning.
Self-promotion
If you have found this useful, then you should follow me, I will be posting more interesting content! 🥰
 GitHub 
 Twitter 
 Dev.to 
Or support me financially. 💸
 GitHub Sponsors 
 LiberaPay 
 PayPal 
Conclusion
Today you have learned how to free up space on your system by removing Docker's unused images, containers, volumes and networks.
 Let me know how much space you have recovered in the comments!
How to remove unused Docker resources
https://blog.akbal.dev/how-to-remove-unused-docker-resources
https://cyberhost.uk/update-all-docker-compose/
Update all Docker Containers with docker-compose
2021-10-19
CyberHost
<div><article>
 <div>
 <p>This command will <code>cd</code> into each directory and then run a command to fetch the latest images and restart the containers if there is an update.</p>
<p>It makes the assumption that you have a directory per service with a docker-compose file within.</p>
<pre><code>for d in ./*/ ; do (cd "$d" &amp;&amp; sudo docker-compose pull &amp;&amp; sudo docker-compose --compatibility up -d); done
</code></pre>
<hr /><p>Cover image credit: <a href="https://unsplash.com/@dilucidus">https://unsplash.com/@dilucidus</a></p>
<p>Last modified: 31st October 2021</p>
 </div>
 </article>||||I|||| * 
 * Home
 * Self-Hosting
 * Cloud
 * Other
 * Quick Tips
 * About

 * Recent articles

 Cloudflare Argo Tunnel Setup - Self-Host with a CG-NAT

 a year ago

 How to Self-Host Matrix and Element (Docker Compose)

 a year ago

 Zorin Mirror Live!

 a year ago

 Manjaro Mirror Live!

 a year ago

 Tags

 + Caddy
 + Cloud
 + Ghost
 + Linux
 + Networking
 + Other
 + Quick Tips
 + Reviews
 + Self-Hosting
 + Tutorials
 Toggle dark mode

 Update all Docker Containers with docker-compose

 This command will cd into each directory and then run a command to fetch the latest images and restart the containers if there is an update.

 It makes the assumption that you have a directory per service with a docker-compose file within.

 for d in ./*/ ; do (cd "$d" && sudo docker-compose pull && sudo docker-compose --compatibility up -d); done
 

 Cover image credit: https://unsplash.com/@dilucidus

 Last modified: 31st October 2021

 Type to search

 No results for your search, please try with something else.

 CyberHost © 2023 • Published with Ghost

 JavaScript license information

 Great! You've successfully subscribed.
 Great! Next, complete checkout for full access.
 Welcome back! You've successfully signed in.
 Success! Your account is fully activated, you now have access to all content.
This command will cd into each directory and then run a command to fetch the latest images and restart the containers if there is an update.
It makes the assumption that you have a directory per service with a docker-compose file within.
 for d in ./*/ ; do (cd "$d" &amp;&amp; sudo docker-compose pull &amp;&amp; sudo docker-compose --compatibility up -d); done
 
 Cover image credit: https://unsplash.com/@dilucidus 
Last modified: 31st October 2021
Update all Docker Containers with docker-compose
https://cyberhost.uk/update-all-docker-compose/
https://docs.docker.com/engine/reference/commandline/volume_rm/
docker volume rm
2023-02-07
None
<div><section>
 
<p>Remove one or more volumes</p>
<h2>Usage</h2>
<div><pre><code>$ docker volume rm [OPTIONS] VOLUME [VOLUME...]
</code></pre></div>
<p>Refer to the <a href="#options">options section</a> for an overview of available <a href="#options"><code>OPTIONS</code></a> for this command.</p>
<h2>Description</h2>
<p>Remove one or more volumes. You cannot remove a volume that is in use by a container.</p>
<p>For example uses of this command, refer to the <a href="#examples">examples section</a> below.</p>
<h2>Options</h2>
<table>
<thead>
 <tr>
 <td>Name, shorthand</td>
 <td>Default</td>
 <td>Description</td>
 </tr>
</thead>
<tbody>
 
 
 
 
 
 
 
 <tr>
 <td><code>--force</code> , <code>-f</code></td>
 <td></td>
 <td>Force the removal of one or more volumes</td>
 </tr>
 
 
 
 
 
 
 
 <tr>
 <td><code>--help</code></td>
 <td></td>
 <td>Print usage</td>
 </tr>
 
</tbody>
</table>
<h2>Examples</h2>
<div><pre><code>$ docker volume rm hello
hello
</code></pre></div>
<h2>Parent command</h2>
<table>
 <thead>
 <tr>
 <th>Command</th>
 <th>Description</th>
 </tr>
 </thead>
 <tbody>
 <tr>
 <td><a href="/engine/reference/commandline/volume/">docker volume</a></td>
 <td>Manage volumes</td>
 </tr>
 </tbody>
</table>
<table>
<thead>
 <tr>
 <td>Command</td>
 <td>Description</td>
 </tr>
</thead>
<tbody>
 
 <tr>
 <td><a href="/engine/reference/commandline/volume_create/">docker volume create</a></td>
 <td>Create a volume</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/volume_inspect/">docker volume inspect</a></td>
 <td>Display detailed information on one or more volumes</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/volume_ls/">docker volume ls</a></td>
 <td>List volumes</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/volume_prune/">docker volume prune</a></td>
 <td>Remove all unused local volumes</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/volume_rm/">docker volume rm</a></td>
 <td>Remove one or more volumes</td>
 </tr>
 
 <tr>
 <td><a href="/engine/reference/commandline/volume_update/">docker volume update</a></td>
 <td>Update a volume (cluster volumes only)</td>
 </tr>
</tbody>
</table>
 </section>||||I|||| Search
 Toggle navigation
 * Home
 * Guides
 * Manuals
 * Reference
 * Samples
 * Contribute
 1. 
 2. Reference
 3. Command-line reference
 4. Docker CLI (docker)
 5. docker volume
 6. docker volume rm

 docker volume rm


 Remove one or more volumes

 Usage

 $ docker volume rm [OPTIONS] VOLUME [VOLUME...]
 

 Refer to the options section for an overview of available OPTIONS for this command.

 Description

 Remove one or more volumes. You cannot remove a volume that is in use by a container.

 For example uses of this command, refer to the examples section below.

 Options

 Name, shorthand Default Description 
 --force , -f Force the removal of one or more volumes
 --help Print usage 
 

 Examples

 $ docker volume rm hello
 
 hello
 

 Parent command

 Command Description 
 docker volume Manage volumes
 

 Related commands

 Command Description 
 docker volume create Create a volume 
 docker volume inspect Display detailed information on one or more volumes
 docker volume ls List volumes 
 docker volume prune Remove all unused local volumes 
 docker volume rm Remove one or more volumes 
 docker volume update Update a volume (cluster volumes only) 
 
 * 
 Contents:
 ×
 Page details
 * Edit this page
 * Request changes
 Contents
 * Usage
 * Description
 * Options
 * Examples
 * Parent command
 * Related commands
 * Product offerings
 * Docker Personal
 * Docker Pro
 * Docker Team
 * Docker Business
 * Compare Subscriptions
 * Features
 * Docker Desktop
 * Docker Hub
 * Secure Software Supply Chain
 * Container Runtime
 * Developer Tools
 * Trusted Content
 * Docker Product Roadmap
 * Developers
 * Use Cases
 * Get Started
 * Blog
 * Community
 * Open Source
 * Preview Program
 * Pricing
 * FAQ
 * Docker Verified Publisher
 * Partners
 * About Us
 * What is a Container?
 * Why Docker?
 * Virtual Events
 * Swag Store
 * Newsroom
 * Careers
 * Contact Us
 * Customers
 * Newsletter
 * Terms of Service
 * Status
 * Legal

 Copyright © 2013-2023 Docker Inc. All rights reserved.

 Cookie Settings
 * Twitter
 * Youtube
 * GitHub
 * Linkedin
 * Facebook
 * Slideshare
 * Reddit
Remove one or more volumes
Usage
  $ docker volume rm [OPTIONS] VOLUME [VOLUME...]
  
Refer to the options section for an overview of available  OPTIONS  for this command.
Description
Remove one or more volumes. You cannot remove a volume that is in use by a container.
For example uses of this command, refer to the examples section below.
Options
 
 Name, shorthand
 Default
 Description
 
 
 
 
 
 
 
 
 
  --force , -f 
  
 Force the removal of one or more volumes
 
 
 
 
 
 
 
 
 
  --help 
  
 Print usage
 
 
Examples
  $ docker volume rm hello
hello
  
Parent command
 
 
 Command
 Description
 
 
 
 
  docker volume 
 Manage volumes
 
 
 
 Command
 Description
 
 
 
  docker volume create 
 Create a volume
 
 
 
  docker volume inspect 
 Display detailed information on one or more volumes
 
 
 
  docker volume ls 
 List volumes
 
 
 
  docker volume prune 
 Remove all unused local volumes
 
 
 
  docker volume rm 
 Remove one or more volumes
 
 
 
  docker volume update 
 Update a volume (cluster volumes only)
docker volume rm
https://docs.docker.com/engine/reference/commandline/volume_rm/
https://www.tutorialspoint.com/docker/docker_images.htm
Docker - Images
2014-06-26
None
<div><div>
<hr />
<p>In Docker, everything is based on Images. An image is a combination of a file system and parameters. Let’s take an example of the following command in Docker.</p>
<pre>docker run hello-world 
</pre>
<ul>
<li><p>The Docker command is specific and tells the Docker program on the Operating System that something needs to be done.</p></li>
<li><p>The <b>run</b> command is used to mention that we want to create an instance of an image, which is then called a <b>container</b>.</p></li>
<li><p>Finally, "hello-world" represents the image from which the container is made.</p></li>
</ul>
<p>Now let’s look at how we can use the CentOS image available in Docker Hub to run CentOS on our Ubuntu machine. We can do this by executing the following command on our Ubuntu machine −</p>
<pre>sudo docker run -it centos /bin/bash
</pre>
<p>Note the following points about the above <b>sudo</b> command −</p>
<ul>
<li><p>We are using the <b>sudo</b> command to ensure that it runs with <b>root</b> access.</p></li>
<li><p>Here, <b>centos</b> is the name of the image we want to download from Docker Hub and install on our Ubuntu machine.</p></li>
<li><p><b>─it</b> is used to mention that we want to run in <b>interactive mode</b>.</p></li>
<li><p><b>/bin/bash</b> is used to run the bash shell once CentOS is up and running.</p></li>
</ul>
<h2>Displaying Docker Images</h2>
<p>To see the list of Docker images on the system, you can issue the following command.</p>
<pre>docker images
</pre>
<p>This command is used to display all the images currently installed on the system.</p>
<h3>Syntax</h3>
<pre>docker images 
</pre>
<h3>Options</h3>
<p>None</p>
<h3>Return Value</h3>
<p>The output will provide the list of images on the system.</p>
<h3>Example</h3>
<pre>sudo docker images
</pre>
<h3>Output</h3>
<p>When we run the above command, it will produce the following result −</p>
<p></p><p>From the above output, you can see that the server has three images: <b>centos, newcentos,</b> and <b>jenkins</b>. Each image has the following attributes −</p>
<ul>
<li><p><b>TAG</b> − This is used to logically tag images.</p></li>
<li><p><b>Image ID</b> − This is used to uniquely identify the image.</p></li>
<li><p><b>Created</b> − The number of days since the image was created.</p></li>
<li><p><b>Virtual Size</b> − The size of the image.</p></li>
</ul>
<h2>Downloading Docker Images</h2>
<p>Images can be downloaded from Docker Hub using the Docker <b>run</b> command. Let’s see in detail how we can do this.</p>
<h3>Syntax</h3>
<p>The following syntax is used to run a command in a Docker container.</p>
<pre>docker run image 
</pre>
<h3>Options</h3>
<ul>
<li><p><b>Image</b> − This is the name of the image which is used to run the container.</p></li>
</ul>
<h3>Return Value</h3>
<p>The output will run the command in the desired container.</p>
<h3>Example</h3>
<pre>sudo docker run centos
</pre>
<p>This command will download the <b>centos</b> image, if it is not already present, and run the OS as a container.</p>
<h3>Output</h3>
<p>When we run the above command, we will get the following result −</p>
<p></p><p>You will now see the CentOS Docker image downloaded. Now, if we run the Docker <b>images</b> command to see the list of images on the system, we should be able to see the <b>centos</b> image as well.</p>
<p></p><h2>Removing Docker Images</h2>
<p>The Docker images on the system can be removed via the <b>docker rmi</b> command. Let’s look at this command in more detail.</p>
<pre>docker rmi
</pre>
<p>This command is used to remove Docker images.</p>
<h3>Syntax</h3>
<pre>docker rmi ImageID
</pre>
<h3>Options</h3>
<ul>
<li><p><b>ImageID</b> − This is the ID of the image which needs to be removed.</p></li>
</ul>
<h3>Return Value</h3>
<p>The output will provide the Image ID of the deleted Image.</p>
<h3>Example</h3>
<pre>sudo docker rmi 7a86f8ffcb25 
</pre>
<p>Here, <b>7a86f8ffcb25</b> is the Image ID of the <b>newcentos</b> image.</p>
<h3>Output</h3>
<p>When we run the above command, it will produce the following result −</p>
<p></p><p>Let’s see some more Docker commands on images.</p>
<h2>docker images -q</h2>
<p>This command is used to return only the Image ID’s of the images.</p>
<h3>Syntax</h3>
<pre>docker images 
</pre>
<h3>Options</h3>
<ul>
<li><p><b>q</b> − It tells the Docker command to return the Image ID’s only.</p></li>
</ul>
<h3>Return Value</h3>
<p>The output will show only the Image ID’s of the images on the Docker host.</p>
<h3>Example</h3>
<pre>sudo docker images -q 
</pre>
<h3>Output</h3>
<p>When we run the above command, it will produce the following result −</p>
<p></p><h2>docker inspect</h2>
<p>This command is used see the details of an image or container.</p>
<h3>Syntax</h3>
<pre>docker inspect Repository 
</pre>
<h3>Options</h3>
<ul>
<li><p><b>Repository</b> − This is the name of the Image.</p></li>
</ul>
<h3>Return Value</h3>
<p>The output will show detailed information on the Image.</p>
<h3>Example</h3>
<pre>sudo docker inspect jenkins 
</pre>
<h3>Output</h3>
<p>When we run the above command, it will produce the following result −</p>
<p></p>
	</div>||||I|||| * Home
 * Coding Ground
 * Jobs
 * Whiteboard
 * Tools
 * Corporate Training
 Teach with us
 * 
 * 
 * 
 * 
 * 
 * Login
 * Category
 + Academic Tutorials
 + Big Data & Analytics
 + Computer Programming
 + Computer Science
 + Databases
 + DevOps
 + Digital Marketing
 + Engineering Tutorials
 + Exams Syllabus
 + Famous Monuments
 + GATE Exams
 + Latest Technologies
 + Machine Learning
 + Mainframe Development
 + Management Tutorials
 + Mathematics Tutorials
 + Microsoft Technologies
 + Misc tutorials
 + Mobile Development
 + Java Technologies
 + Python Technologies
 + SAP Tutorials
 + Programming Scripts
 + Selected Reading
 + Software Quality
 + Soft Skills
 + Telecom Tutorials
 + UPSC IAS Exams
 + Web Development
 + Sports Tutorials
 + XML Technologies
 + Multi-Language
 + Interview Questions
 * Prime Packs
 * Courses
 * eBooks
 * Library
 * Articles
 Login
 * Docker Tutorial
 * Docker - Home
 * Docker - Overview
 * Docker - Installing Docker on Linux
 * Docker - Installation
 * Docker - Hub
 * Docker - Images
 * Docker - Containers
 * Docker - Working With Containers
 * Docker - Architecture
 * Docker - Container & Hosts
 * Docker - Configuring
 * Docker - Containers & Shells
 * Docker - File
 * Docker - Building Files
 * Docker - Public Repositories
 * Docker - Managing Ports
 * Docker - Private Registries
 * Building a Web Server Docker File
 * Docker - Instruction Commands
 * Docker - Container Linking
 * Docker - Storage
 * Docker - Networking
 * Docker - Setting Node.js
 * Docker - Setting MongoDB
 * Docker - Setting NGINX
 * Docker - Toolbox
 * Docker - Setting ASP.Net
 * Docker - Cloud
 * Docker - Logging
 * Docker - Compose
 * Docker - Continuous Integration
 * Docker - Kubernetes Architecture
 * Docker - Working of Kubernetes
 * Docker Useful Resources
 * Docker - Quick Guide
 * Docker - Useful Resources
 * Docker - Discussion
 * Selected Reading
 * UPSC IAS Exams Notes
 * Developer's Best Practices
 * Questions and Answers
 * Effective Resume Writing
 * HR Interview Questions
 * Computer Glossary
 * Who is Who

 Docker - Images

 Previous Page
 Next Page

 In Docker, everything is based on Images. An image is a combination of a file system and parameters. Let’s take an example of the following command in Docker.

 
 docker run hello-world 
 

 * The Docker command is specific and tells the Docker program on the Operating System that something needs to be done.

 * The run command is used to mention that we want to create an instance of an image, which is then called a container.

 * Finally, "hello-world" represents the image from which the container is made.

 Now let’s look at how we can use the CentOS image available in Docker Hub to run CentOS on our Ubuntu machine. We can do this by executing the following command on our Ubuntu machine −

 
 sudo docker run -it centos /bin/bash
 

 Note the following points about the above sudo command −

 * We are using the sudo command to ensure that it runs with root access.

 * Here, centos is the name of the image we want to download from Docker Hub and install on our Ubuntu machine.

 * ─it is used to mention that we want to run in interactive mode.

 * /bin/bash is used to run the bash shell once CentOS is up and running.

 Displaying Docker Images

 To see the list of Docker images on the system, you can issue the following command.

 
 docker images
 

 This command is used to display all the images currently installed on the system.

 Syntax

 
 docker images 
 

 Options

 None

 Return Value

 The output will provide the list of images on the system.

 Example

 
 sudo docker images
 

 Output

 When we run the above command, it will produce the following result −

 From the above output, you can see that the server has three images: centos, newcentos, and jenkins. Each image has the following attributes −

 * TAG − This is used to logically tag images.

 * Image ID − This is used to uniquely identify the image.

 * Created − The number of days since the image was created.

 * Virtual Size − The size of the image.

 Downloading Docker Images

 Images can be downloaded from Docker Hub using the Docker run command. Let’s see in detail how we can do this.

 Syntax

 The following syntax is used to run a command in a Docker container.

 
 docker run image 
 

 Options

 * Image − This is the name of the image which is used to run the container.

 Return Value

 The output will run the command in the desired container.

 Example

 
 sudo docker run centos
 

 This command will download the centos image, if it is not already present, and run the OS as a container.

 Output

 When we run the above command, we will get the following result −

 You will now see the CentOS Docker image downloaded. Now, if we run the Docker images command to see the list of images on the system, we should be able to see the centos image as well.

 Removing Docker Images

 The Docker images on the system can be removed via the docker rmi command. Let’s look at this command in more detail.

 
 docker rmi
 

 This command is used to remove Docker images.

 Syntax

 
 docker rmi ImageID
 

 Options

 * ImageID − This is the ID of the image which needs to be removed.

 Return Value

 The output will provide the Image ID of the deleted Image.

 Example

 
 sudo docker rmi 7a86f8ffcb25 
 

 Here, 7a86f8ffcb25 is the Image ID of the newcentos image.

 Output

 When we run the above command, it will produce the following result −

 Let’s see some more Docker commands on images.

 docker images -q

 This command is used to return only the Image ID’s of the images.

 Syntax

 
 docker images 
 

 Options

 * q − It tells the Docker command to return the Image ID’s only.

 Return Value

 The output will show only the Image ID’s of the images on the Docker host.

 Example

 
 sudo docker images -q 
 

 Output

 When we run the above command, it will produce the following result −

 docker inspect

 This command is used see the details of an image or container.

 Syntax

 
 docker inspect Repository 
 

 Options

 * Repository − This is the name of the Image.

 Return Value

 The output will show detailed information on the Image.

 Example

 
 sudo docker inspect jenkins 
 

 Output

 When we run the above command, it will produce the following result −

 Previous Page Print Page Next Page
 Advertisements


 Annual Membership

 Enjoy unlimited access on 5500+ Hand Picked Quality Video Courses

 Subscribe Now

 Training for a Team

 Affordable solution to train a team and make them project ready.

 Submit Demo Request
 * About us
 * Refund Policy
 * Terms of use
 * Privacy Policy
 * FAQ's
 * Contact

 © Copyright 2023. All Rights Reserved.

 We make use of First and third party cookies to improve our user experience. By using this website, you agree with our Cookies Policy. Agree Learn more

In Docker, everything is based on Images. An image is a combination of a file system and parameters. Let’s take an example of the following command in Docker.
docker run hello-world 
 The Docker command is specific and tells the Docker program on the Operating System that something needs to be done. 
 The run command is used to mention that we want to create an instance of an image, which is then called a container. 
 Finally, "hello-world" represents the image from which the container is made. 
Now let’s look at how we can use the CentOS image available in Docker Hub to run CentOS on our Ubuntu machine. We can do this by executing the following command on our Ubuntu machine −
sudo docker run -it centos /bin/bash
Note the following points about the above sudo command −
 We are using the sudo command to ensure that it runs with root access. 
 Here, centos is the name of the image we want to download from Docker Hub and install on our Ubuntu machine. 
  ─it is used to mention that we want to run in interactive mode. 
  /bin/bash is used to run the bash shell once CentOS is up and running. 
Displaying Docker Images
To see the list of Docker images on the system, you can issue the following command.
docker images
This command is used to display all the images currently installed on the system.
Syntax
docker images 
Options
None
Return Value
The output will provide the list of images on the system.
Example
sudo docker images
Output
When we run the above command, it will produce the following result −
  From the above output, you can see that the server has three images: centos, newcentos, and jenkins. Each image has the following attributes −
  TAG − This is used to logically tag images. 
  Image ID − This is used to uniquely identify the image. 
  Created − The number of days since the image was created. 
  Virtual Size − The size of the image. 
Downloading Docker Images
Images can be downloaded from Docker Hub using the Docker run command. Let’s see in detail how we can do this.
Syntax
The following syntax is used to run a command in a Docker container.
docker run image 
Options
  Image − This is the name of the image which is used to run the container. 
Return Value
The output will run the command in the desired container.
Example
sudo docker run centos
This command will download the centos image, if it is not already present, and run the OS as a container.
Output
When we run the above command, we will get the following result −
  You will now see the CentOS Docker image downloaded. Now, if we run the Docker images command to see the list of images on the system, we should be able to see the centos image as well.
  Removing Docker Images
The Docker images on the system can be removed via the docker rmi command. Let’s look at this command in more detail.
docker rmi
This command is used to remove Docker images.
Syntax
docker rmi ImageID
Options
  ImageID − This is the ID of the image which needs to be removed. 
Return Value
The output will provide the Image ID of the deleted Image.
Example
sudo docker rmi 7a86f8ffcb25 
Here, 7a86f8ffcb25 is the Image ID of the newcentos image.
Output
When we run the above command, it will produce the following result −
  Let’s see some more Docker commands on images.
docker images -q
This command is used to return only the Image ID’s of the images.
Syntax
docker images 
Options
  q − It tells the Docker command to return the Image ID’s only. 
Return Value
The output will show only the Image ID’s of the images on the Docker host.
Example
sudo docker images -q 
Output
When we run the above command, it will produce the following result −
  docker inspect
This command is used see the details of an image or container.
Syntax
docker inspect Repository 
Options
  Repository − This is the name of the Image. 
Return Value
The output will show detailed information on the Image.
Example
sudo docker inspect jenkins 
Output
When we run the above command, it will produce the following result −
Docker - Images
https://www.tutorialspoint.com/docker/docker_images.htm