{"id":1160,"date":"2014-09-07T23:46:12","date_gmt":"2014-09-07T22:46:12","guid":{"rendered":"http:\/\/www.tekhead.org\/blog\/?p=1160"},"modified":"2016-02-24T12:55:16","modified_gmt":"2016-02-24T12:55:16","slug":"docker-part-2-howto-remove-delete-docker-containers","status":"publish","type":"post","link":"http:\/\/tekhead.it\/blog\/2014\/09\/docker-part-2-howto-remove-delete-docker-containers\/","title":{"rendered":"Docker Part 2 &#8211; HOWTO Remove \/ Delete Docker Containers"},"content":{"rendered":"<p>So you have been messing with docker for a few minutes or hours, and now you have a bunch of either running or stopped containers you no longer need. How do you get rid of them?<\/p>\n<h4>Removing Single Containers<\/h4>\n<p>To remove a <em>single<\/em> docker container, you simply start by listing all of the docker containers (started or stopped)\u00a0to ensure you know which one to delete:<\/p>\n<pre>$ sudo docker ps \u2013a<\/pre>\n<p><br style=\"height: 1em;\" \/>Then remove the chosen container:<\/p>\n<pre>$ sudo docker rm &lt;container name&gt;<\/pre>\n<p><br style=\"height: 1em;\" \/>If the container is currently running you can simply add \u2013f to stop and remove the container in a single command:<\/p>\n<pre>$ docker rm -f &lt;container name&gt;<\/pre>\n<p><br style=\"height: 1em;\" \/>Unless it&#8217;s paused, then you will get an error something like the following:<\/p>\n<pre>Error response from daemon: Could not kill running container, cannot remove - Container e4f28eccb0cbcfbf4d78104bfe3e84039f62c5073f7301f8a39bb77a9598ae72 is paused. Unpause the container before stopping<\/pre>\n<p><br style=\"height: 1em;\" \/>This is easy to resolve. The &#8220;docker pause&#8221; command was added as of Docker 1.0, <span style=\"color: #333333;\">allowing for better resource utilisation\u00a0if you have containers you don&#8217;t currently need to be wasting CPU cycles. As of Docker 1.1, running containers are also paused during commit activities, to ensure a consistent file system.<\/span>\u00a0Simply check the ID of the VM (with a ps command), unpause it, then remove:<\/p>\n<pre>sudo docker ps\nsudo docker unpause &lt;container id&gt;\nsudo docker rm -f &lt;container id&gt;<\/pre>\n<p>&nbsp;<\/p>\n<h4>Removing Multiple\u00a0Containers<\/h4>\n<p>Sometimes we have built up a number\u00a0of containers and we just want to scrub the lot in one go. If you want to remove <em>all containers<\/em> (running or not), first you need to generate a list of all of the container IDs, then you pass that list to the docker rm command as follows:<\/p>\n<pre>sudo docker rm -f $(sudo docker ps -aq)<\/pre>\n<p><br style=\"height: 1em;\" \/>Alternatively if you wish to remove <em>only the non-running<\/em> containers:<\/p>\n<pre>sudo docker rm $(sudo docker ps -q)<\/pre>\n<p>&nbsp;<\/p>\n<p>That\u2019ll do for now, but in the next post I will go into how to install your first app\u2026<\/p>\n<p>http:\/\/www.tekhead.org\/blog\/2016\/02\/docker-part-3-howto-create-a-simple-python-web-app-in-docker\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So you have been messing with docker for a few minutes or hours, and now you have a bunch of either running or stopped containers you no longer [..]<\/p>\n","protected":false},"author":1,"featured_media":1157,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_yoast_wpseo_focuskw":"","_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[337],"tags":[340,339,335,342,332,351,344,343,345,350,58],"class_list":["post-1160","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker-2","tag-1-2-0","tag-14-04","tag-apparmor","tag-containers","tag-docker","tag-howto","tag-images","tag-remove","tag-rm","tag-tutorial","tag-ubuntu"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"http:\/\/tekhead.it\/wp-uploads\/www.tekhead.org\/2014\/09\/dockerlogo-e1452888993804.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2l3lU-iI","amp_enabled":true,"_links":{"self":[{"href":"http:\/\/tekhead.it\/blog\/wp-json\/wp\/v2\/posts\/1160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/tekhead.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/tekhead.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/tekhead.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tekhead.it\/blog\/wp-json\/wp\/v2\/comments?post=1160"}],"version-history":[{"count":0,"href":"http:\/\/tekhead.it\/blog\/wp-json\/wp\/v2\/posts\/1160\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/tekhead.it\/blog\/wp-json\/wp\/v2\/media\/1157"}],"wp:attachment":[{"href":"http:\/\/tekhead.it\/blog\/wp-json\/wp\/v2\/media?parent=1160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/tekhead.it\/blog\/wp-json\/wp\/v2\/categories?post=1160"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/tekhead.it\/blog\/wp-json\/wp\/v2\/tags?post=1160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}