When Containers Become Trashcans
Tags: docker, containers, productivity
Published: 2020-03-01 19:39:47

---
title: "When Containers Become Trashcans"
description: Docker containers are really awesome, powerful, and useful to the modern developer, but if you aren't mindful, those unused ones can quickly turn from containers to trashcans that can make your development environment a stinky place to work in.
tags: docker, containers, productivity
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/0n17267q9vtlba0wzuus.jpg
published: true
---

Containers are *so* awesome.

Prior to containers, if you wanted to experiment with some new technology, you had to go through the ringer to configure and install all of the appropriate dependencies, set up the proper infrastructure, and clutter your machine with tons of trash that you might not ever care to use in the future. Thankfully, Docker and other containerized technologies came along and empowered developers to just throw a one-liner into the command line and like magic, the entire world appeared in a magical little box.

Several days ago, I had an idea in my head so I scrounged around through [Docker Hub](https://hub.docker.com/) looking for the perfect container that had everything that I wanted in it. I'd pull down one, tinker a bit, and throw it away. Pull another down, try something else, and then eventually throw it away. Pull yet another one down and ... crap!

```language-bash
docker: write /var/lib/docker/tmp/GetImageBlob785934359: no space left on device.
```

No space left on my device? That's odd, maybe it's the hours upon hours of videos that I've downloaded for my kids to watch on road trips, or all those computer games that I've installed but never can find the time to play (some day)? Let me check out the hard-drive and see how that looks:

![look mom plenty of space](http://rion.io/content/images/2020/02/no-that-bad.PNG)

Okay, so either this image that I'm pulling down is _really_ big, or something else is going on. After a bit of mulling it over, I realized that like all good humans that don't want [the machines taking over](https://en.wikipedia.org/wiki/Technological_singularity), delegated a specific amount of space and resources that Docker could take advantage and sure enough, I was right at the threshold.

It was time to take out the trash, however since <code class='language-bash'>docker dump trash</code> isn't a legitimate command (at least out of the box), I just had to do a quick prune:

```language-bash
docker system prune
```

The prune command in a nutshell does the following:

- Removes all non-running / stopped containers
- Removes all volumes that aren't being used (by at least one active container)
- Removes all networks that aren't being used (by at least one active container)
- Removes all dangling images within the system.

Since I mentioned above that I _really_ enjoy playing with containers, I figured that we'd just do it live, so here's what that looked like on my local machine:

![as if millions of containers cried out](https://dev-to-uploads.s3.amazonaws.com/i/hqaq2ppn6nc9hwqvp1um.gif)

**With three little words, I managed to free up nearly 126GB of unused space across 22 containers, 5 networks, and 45 images).** That's quite impressive, but more importantly, I was then able to immediately install the image that I was trying to in the first place. 

So the moral of the story is this - containers are really awesome, powerful, and useful to the modern developer, but if you aren't mindful, those unused ones can quickly turn from containers to trashcans that can make your development environment a stinky place to work in.