<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Bevan</title>
    <description>The latest articles on Forem by Bevan (@bevan).</description>
    <link>https://forem.com/bevan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F435466%2Fd55ad952-2d7c-474d-af72-248c2a1b6cd8.png</url>
      <title>Forem: Bevan</title>
      <link>https://forem.com/bevan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/bevan"/>
    <language>en</language>
    <item>
      <title>Quick one liner to purge docker containers and images</title>
      <dc:creator>Bevan</dc:creator>
      <pubDate>Sun, 19 Jul 2020 13:59:01 +0000</pubDate>
      <link>https://forem.com/bevan/quick-one-liner-to-purge-docker-containers-and-images-3hnb</link>
      <guid>https://forem.com/bevan/quick-one-liner-to-purge-docker-containers-and-images-3hnb</guid>
      <description>&lt;p&gt;Does what it says on the tin. I'm using &lt;a href="https://fishshell.com/"&gt;fish&lt;/a&gt; so my one liner looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker rm (docker ps -a -q) &amp;amp;&amp;amp; docker rmi -f (docker image ls -q)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you're running a more standard shell like bash, you'll probably need some &lt;code&gt;$&lt;/code&gt;s in there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker rm $(docker ps -a -q) &amp;amp;&amp;amp; docker rmi -f $(docker image ls -q)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It's pretty simple - &lt;code&gt;docker rm&lt;/code&gt; removes containers. It accepts a list of container Ids. &lt;code&gt;docker ps -a -q&lt;/code&gt; lists all containers in quiet mode - so just the container Ids.&lt;/p&gt;

&lt;p&gt;The logic is the same for removing images - I've thrown in the &lt;code&gt;f&lt;/code&gt; force flag for good measure, and I've used &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; to concatenate two commands onto one line.&lt;/p&gt;

&lt;p&gt;This will error out if you have no containers. Be warned.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>containers</category>
      <category>images</category>
      <category>delete</category>
    </item>
  </channel>
</rss>
