Tuesday, September 1, 2020

Retiring Old Docker Containers in Dokku Environment

I love Dokku and I've been using it more more than 6 years to host production applications. It really steamlines the deployment of new releases and it is such a handy platform for developers to move into serious app release cycles.

If there is one pain point I have had over the years by using Dokku; it will have to be the "Docker baggage" the runtime leaves behinds over time. I have had situations where my servers run out of memory or disk space, and upon digging deeper into the issue I discover that it's caused due to issues like old Docker containers (Dokku is basically an abstraction layer over Docker) that keep running even after a new version of your app launches into a new Docker container or where the (sometimes) retired Docker Images still being left behind consum a lot of disk space.

I've seen numerous issues on the Dokku Github page like this - Old commit's containers do not ever shut down - which have been long closed as resolved, but I've always seen the issues continue.

I've blogged previously about how to cleanup Docker images here Dokku app deployment fails with a “main: command not found. access denied”. Its most likely a storage space issue... but in this post I will walk you through a "deep clean" I did on my live application http://wisdomtoinspire.com/ - which is powered by 3 Dokku apps and a MondoDB container running on a server.

The following is highly risky as you have to deal with docker directly but if you know what you are doing then it should be OK. (but do these at your own RISK!)

Step 1: Start with a benchmark of memory and disk space to see how much you are actually saving.

Memory: run this command in the terminal:

free -m 

Diskspace: run the command:

df -h 

in the terminal. /dev/disk... is you hard-disk, but you will also see the junk Docker containers here listed which hopefully we can clean up