{"id":9513,"date":"2022-07-27T16:30:50","date_gmt":"2022-07-27T11:00:50","guid":{"rendered":"https:\/\/www.skynats.com\/?p=9513"},"modified":"2023-06-15T17:09:08","modified_gmt":"2023-06-15T11:39:08","slug":"remove-exited-containers-in-docker","status":"publish","type":"post","link":"https:\/\/www.skynats.com\/blog\/remove-exited-containers-in-docker\/","title":{"rendered":"How To Remove Exited Containers In Docker?"},"content":{"rendered":"\n<p>Considering removing exited containers in Docker? Our <a href=\"https:\/\/www.skynats.com\/devops-support\/\" target=\"_blank\" rel=\"noreferrer noopener\">Docker Support<\/a> team has the answer. Now let&#8217;s determine what those are.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-removing-exited-containers-in-docker\">Removing Exited Containers in Docker<\/h2>\n\n\n\n<p>Docker makes it simple to collect an excessive number of exited containers, which clutter the output and utilize disc space. Docker also offers command-line tools for system cleanup.<\/p>\n\n\n\n<p>If we know beforehand that a container will not be around for long, we can use the command below to delete it when it exits:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run --rm image_name<\/code><\/pre>\n\n\n\n<p>Additionally, we can use docker ps -a to locate containers and filter them according to their status: created, restarting, running, paused, or exited. Utilize the -f flag to filter the list of exited containers according to their status. When we are certain that we want to remove these containers, we can pass their IDs to the docker rm command with the -q flag.<\/p>\n\n\n\n<p>To obtain a list of the exited containers, enter the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker ps -a -f status=exited<\/code><\/pre>\n\n\n\n<p>Afterward, we can use the following command to remove the exited containers:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker rm $(docker ps -a -f status=exited -f status=created -q)<\/code><\/pre>\n\n\n\n<p>Additional commands for removing exited containers include:<\/p>\n\n\n\n<p>We can use any of the following commands to remove all containers that have exited:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs sudo docker rm<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>$ docker rm $(docker ps -a -q -f status=exited)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>(docker ps -a |findstr Exited) | foreach-object {docker rm $_.split(\" \")&#91;-1]}<\/code><\/pre>\n\n\n\n<p>Since Docker 1.13.x, Docker container prune can be used to remove all stopped containers. This will function identically across all platforms. The following is the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ docker container prune\nWARNING! This will remove all stopped containers.\nAre you sure you want to continue? &#91;y\/N] y\nDeleted Containers:\n4a9f7edbae0f63178aff7eb0aa39f0627a203ab2df258c1a00b456cf20063\nf98f9c2aa1eaf727e4ea9c0283bcaa4762fbdba7f36191f26c97f64090361 Total reclaimed space: 212 B<\/code><\/pre>\n\n\n\n<p>There is also a Docker system prune that removes unused containers with a single command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker system prune -a\n\nWARNING! This will remove:\n    - all stopped containers\n    - all volumes not used by at least one container\n    - all images without at least one container associated to them\nAre you sure you want to continue? &#91;y\/N] y<\/code><\/pre>\n\n\n\n<p>For older versions of Docker, it is possible to combine it with other Unix commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ docker ps --filter \"status=exited\" | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm<\/code><\/pre>\n\n\n\n<p>The following command will remove all containers:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker rm `docker ps --no-trunc -aq`<\/code><\/pre>\n\n\n\n<p>For Windows, this will be the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FOR \/f \"tokens=*\" %i IN ('docker ps -a -q') DO docker rm %i<\/code><\/pre>\n\n\n\n<p>For PowerShell, this will be the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker rm @(docker ps -aq)<\/code><\/pre>\n\n\n\n<p><strong>Summary<\/strong><\/p>\n\n\n\n<p>Docker simplifies the containerization of applications and services, allowing them to run anywhere. It is easy to accumulate an excessive number of unutilized images, containers, and data volumes when working with Docker, which clutters the output and utilizes disc space. This article describes a variety of Docker container removal methods.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Considering removing exited containers in Docker? Our Docker Support team has the answer. Now let&#8217;s determine what those are. Removing Exited Containers in Docker Docker makes it simple to collect an excessive number of exited containers, which clutter the output and utilize disc space. Docker also offers command-line tools for system cleanup. If we know [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[85],"class_list":["post-9513","post","type-post","status-publish","format-standard","hentry","category-blog","tag-docker"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How To Remove Exited Containers In Docker? | Skynats<\/title>\n<meta name=\"description\" content=\"Considering removing exited containers in Docker? Our Docker Support team has the answer. Determine what those are.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.skynats.com\/blog\/remove-exited-containers-in-docker\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Remove Exited Containers In Docker?\" \/>\n<meta property=\"og:description\" content=\"Considering removing exited containers in Docker? Our Docker Support team has the answer. Determine what those are.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.skynats.com\/blog\/remove-exited-containers-in-docker\/\" \/>\n<meta property=\"og:site_name\" content=\"Server Management Services | Cloud Management | Skynats\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/skynats\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-27T11:00:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-15T11:39:08+00:00\" \/>\n<meta name=\"author\" content=\"Arjun N\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@skynatstech\" \/>\n<meta name=\"twitter:site\" content=\"@skynatstech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Arjun N\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/remove-exited-containers-in-docker\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/remove-exited-containers-in-docker\\\/\"},\"author\":{\"name\":\"Arjun N\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#\\\/schema\\\/person\\\/2428d280a8b32a1fbd909b1411e32fb7\"},\"headline\":\"How To Remove Exited Containers In Docker?\",\"datePublished\":\"2022-07-27T11:00:50+00:00\",\"dateModified\":\"2023-06-15T11:39:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/remove-exited-containers-in-docker\\\/\"},\"wordCount\":322,\"publisher\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#organization\"},\"keywords\":[\"docker\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/remove-exited-containers-in-docker\\\/\",\"url\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/remove-exited-containers-in-docker\\\/\",\"name\":\"How To Remove Exited Containers In Docker? | Skynats\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#website\"},\"datePublished\":\"2022-07-27T11:00:50+00:00\",\"dateModified\":\"2023-06-15T11:39:08+00:00\",\"description\":\"Considering removing exited containers in Docker? Our Docker Support team has the answer. Determine what those are.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/remove-exited-containers-in-docker\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.skynats.com\\\/blog\\\/remove-exited-containers-in-docker\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/remove-exited-containers-in-docker\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Remove Exited Containers In Docker?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/\",\"name\":\"Server Management Services | Cloud Management | Skynats\",\"description\":\"Server Management and Cloud Management\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#organization\",\"name\":\"Skynats Technologies\",\"url\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/08\\\/Sknats-Logo-New-whole.png\",\"contentUrl\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/08\\\/Sknats-Logo-New-whole.png\",\"width\":989,\"height\":367,\"caption\":\"Skynats Technologies\"},\"image\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/skynats\",\"https:\\\/\\\/x.com\\\/skynatstech\",\"https:\\\/\\\/www.instagram.com\\\/skynatstech\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/skynats-technologies\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCvTAjrFJ4_E2MJKwlDHomlg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#\\\/schema\\\/person\\\/2428d280a8b32a1fbd909b1411e32fb7\",\"name\":\"Arjun N\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e0f4d2489abeea1769beb944d2258c862259b62ff26853075066ca8ad37e3333?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e0f4d2489abeea1769beb944d2258c862259b62ff26853075066ca8ad37e3333?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e0f4d2489abeea1769beb944d2258c862259b62ff26853075066ca8ad37e3333?s=96&d=mm&r=g\",\"caption\":\"Arjun N\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How To Remove Exited Containers In Docker? | Skynats","description":"Considering removing exited containers in Docker? Our Docker Support team has the answer. Determine what those are.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.skynats.com\/blog\/remove-exited-containers-in-docker\/","og_locale":"en_US","og_type":"article","og_title":"How To Remove Exited Containers In Docker?","og_description":"Considering removing exited containers in Docker? Our Docker Support team has the answer. Determine what those are.","og_url":"https:\/\/www.skynats.com\/blog\/remove-exited-containers-in-docker\/","og_site_name":"Server Management Services | Cloud Management | Skynats","article_publisher":"https:\/\/www.facebook.com\/skynats","article_published_time":"2022-07-27T11:00:50+00:00","article_modified_time":"2023-06-15T11:39:08+00:00","author":"Arjun N","twitter_card":"summary_large_image","twitter_creator":"@skynatstech","twitter_site":"@skynatstech","twitter_misc":{"Written by":"Arjun N","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.skynats.com\/blog\/remove-exited-containers-in-docker\/#article","isPartOf":{"@id":"https:\/\/www.skynats.com\/blog\/remove-exited-containers-in-docker\/"},"author":{"name":"Arjun N","@id":"https:\/\/www.skynats.com\/blog\/#\/schema\/person\/2428d280a8b32a1fbd909b1411e32fb7"},"headline":"How To Remove Exited Containers In Docker?","datePublished":"2022-07-27T11:00:50+00:00","dateModified":"2023-06-15T11:39:08+00:00","mainEntityOfPage":{"@id":"https:\/\/www.skynats.com\/blog\/remove-exited-containers-in-docker\/"},"wordCount":322,"publisher":{"@id":"https:\/\/www.skynats.com\/blog\/#organization"},"keywords":["docker"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.skynats.com\/blog\/remove-exited-containers-in-docker\/","url":"https:\/\/www.skynats.com\/blog\/remove-exited-containers-in-docker\/","name":"How To Remove Exited Containers In Docker? | Skynats","isPartOf":{"@id":"https:\/\/www.skynats.com\/blog\/#website"},"datePublished":"2022-07-27T11:00:50+00:00","dateModified":"2023-06-15T11:39:08+00:00","description":"Considering removing exited containers in Docker? Our Docker Support team has the answer. Determine what those are.","breadcrumb":{"@id":"https:\/\/www.skynats.com\/blog\/remove-exited-containers-in-docker\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.skynats.com\/blog\/remove-exited-containers-in-docker\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.skynats.com\/blog\/remove-exited-containers-in-docker\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.skynats.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How To Remove Exited Containers In Docker?"}]},{"@type":"WebSite","@id":"https:\/\/www.skynats.com\/blog\/#website","url":"https:\/\/www.skynats.com\/blog\/","name":"Server Management Services | Cloud Management | Skynats","description":"Server Management and Cloud Management","publisher":{"@id":"https:\/\/www.skynats.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.skynats.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.skynats.com\/blog\/#organization","name":"Skynats Technologies","url":"https:\/\/www.skynats.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.skynats.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.skynats.com\/blog\/wp-content\/uploads\/2021\/08\/Sknats-Logo-New-whole.png","contentUrl":"https:\/\/www.skynats.com\/blog\/wp-content\/uploads\/2021\/08\/Sknats-Logo-New-whole.png","width":989,"height":367,"caption":"Skynats Technologies"},"image":{"@id":"https:\/\/www.skynats.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/skynats","https:\/\/x.com\/skynatstech","https:\/\/www.instagram.com\/skynatstech\/","https:\/\/www.linkedin.com\/company\/skynats-technologies","https:\/\/www.youtube.com\/channel\/UCvTAjrFJ4_E2MJKwlDHomlg"]},{"@type":"Person","@id":"https:\/\/www.skynats.com\/blog\/#\/schema\/person\/2428d280a8b32a1fbd909b1411e32fb7","name":"Arjun N","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e0f4d2489abeea1769beb944d2258c862259b62ff26853075066ca8ad37e3333?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e0f4d2489abeea1769beb944d2258c862259b62ff26853075066ca8ad37e3333?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e0f4d2489abeea1769beb944d2258c862259b62ff26853075066ca8ad37e3333?s=96&d=mm&r=g","caption":"Arjun N"}}]}},"_links":{"self":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/9513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/comments?post=9513"}],"version-history":[{"count":0,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/9513\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/media?parent=9513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/categories?post=9513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/tags?post=9513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}