Clean up old Docker images

Sorry for not posting in a while, I have been a bit busy. Here’s a quick tip.

The Problem

Ideally when running in the cloud we want to be able to ditch our VMs when they misbehave rather than trying to fix them. Reincarnate, don’t resurrect.

For me, however, I am running a single VM (Digital Ocean Droplet) with Docker. I want to be able to recreate my droplet very quickly should things go wrong, but I don’t care much about 100% uptime on my personal server. The issue with this approach is that my SSD fills up quickly with multiple Docker image layers.

The Solution

Despite my droplet being fairly quick to restore, this would be overkill for a simple ‘disk full’ issue. I reclaim my disk space using the prune functions in Docker.

The aggressive approach

This will clean up everything that is unused, use with caution.

# docker system prune

You can be more specific with these commands, pruning individual unused Docker objects

# docker container prune
# docker image prune
# docker network prune
# docker volume prune

Sources

  1. https://docs.docker.com/engine/reference/commandline/system_prune/
  2. https://docs.docker.com/engine/admin/pruning/#prune-everything