Disclaimer: I host several Discourse forums, however, I’m not a coder by trade. This is information that I personally struggled to find when I first started hosting my own forums. How to reclaim space from docker was one of these things! The document referenced in this post is available here if you want a deeper dive!
Always start by creating and downloading a backup of your forum!
If something goes wrong, at least you can quickly get set up with a new instance if you have a solid backup of your forum!
Then, update & upgrade system!
Make sure everything else on the server is set up properly and up to date to minimize any misshaps! Do the following:
sudo apt update
Then do:
sudo apt upgrade
Reclaim space?
If you host a Discourse forum yourself at some point you will notice the disc will fill up and no mather how much you try to clear the Discourse cache will get your precious space back. That’s because Discourse is hosted on Docker and Docker tend to save a lot of stuff when it does its updates etc.
”Docker takes a conservative approach to cleaning up unused objects (often referred to as “garbage collection”), such as images, containers, volumes, and networks: these objects are generally not removed unless you explicitly ask Docker to do so. This can cause Docker to use extra disk space.”
To get that space back is very easily done if you have root access to the command line!
Before we start, make sure you’re in sudo mode!
sudo -s
How to reclaim space from docker
First of all, the command I generally use to clean up the drive!
docker system prune
If you want to remove everything not currently in use there is a command for that as well! For example, if you only have a Discourse instance set up and running, there’s really nothing else that can be affected by pruning. After a few updates and I see the space starting to fill up I tend to just run the docker system prune
command to quickly remove anything that’s not running. This tend to free up all the space I need so we can continue running our Discourse forum in peace!
If you want a more conservative approach, or know exactly what you want removed, see the following commands below:
Pune Images
The first command to remove unwanted images is the Prune images-command and it looks like this:
docker image prune -a
This command will remove any image that is not connected (tagged or referenced) to any currently in use image. Docker uses ”dangling” as to describe the images not in use.
Prune Containers
Similar to images, containers can also take up a lot of space. To prune (remove) them, use the following command:
docker container prune
This command will remove any and all stopped containers. Containers still running will not be affected by this.
Prune Volumes
Last but not least is the command to remove any unused volumes!
docker volume prune
This command will remove any and all volumes not currently in use by at least one container.
Hopefully now you have your precious space back and can continue using Discourse the way it’s meant to be used!
Need help with Discourse?
Are you looking to host your own Discourse forum and need help setting it up with or without hosting? Don’t hesitate to contact me here!
Leave a Reply