Reducing Docker directory size

My YunoHost server

Hardware: Hetzner VPS, 40 GB
YunoHost version: 11.0.10.2
I have access to my server : Through SSH
Are you in a special context or did you perform some particular tweaking on your YunoHost instance ? : no
Relevant apps: GitLab

Disclaimer: I already solved this support request, and I’m posting it here for legacy and potentially any comments about how my solution has doomed my installation.

Description of my issue

While exploring my YunoHost server in an attempt to increase available storage, I discovered that /var/lib/docker/ occupies ~6GiB.

Given that docker was not installed on my system, it took me some time to determine that these directories were being created by GitLab’s CI pipelines.

Here’s the output of tree /var/lib/docker (negligible file/dir sizes are not indicated):

[ 5.7GiB]  /var/lib/docker
β”œβ”€β”€ [ 3.7 GiB]  overlay2
β”‚   β”œβ”€β”€ [ 520 MiB ]  103222...
β”‚   β”œβ”€β”€ [ 520 MiB ]  194cda...
β”‚   └── 20 more containers of various sizes
└── [ 1.9 GiB ]  volumes
    β”œβ”€β”€ [ 920 MiB ]  runner-d8ed6mmy-project-2-concurrent-0-cache-...
    β”œβ”€β”€ [ 500 MiB ]  runner-d8ed6mmy-project-4-concurrent-0-cache-...
    β”œβ”€β”€ a few other volumes of various sizes
    β”œβ”€β”€ backingFsBlockDev
    └── metadata.db
β”œβ”€β”€ buildkit
β”œβ”€β”€ containers
β”œβ”€β”€ image
β”œβ”€β”€ network
β”œβ”€β”€ plugins
β”œβ”€β”€ runtimes
β”œβ”€β”€ swarm
β”œβ”€β”€ tmp
└── trust

Solution

After researching this, I did the following:

  1. Install docker to be able to interact with it (as it is not exposed by GitLab)
  2. Have a look at how docker is being used on your system, to get an idea of what you can clean/should not touch
    • sudo docker ps -a for running containers
    • sudo docker images for existing images
    • sudo docker volume ls for existing volumes
    • sudo docker images -f "dangling=true" for images without containers
    • sudo docker system df for docker disk usage
  3. Clean images and containers (based on discussions here and here)
    • sudo docker image prune --all for removing unused images
    • sudo docker system prune --all for removing unused data
    • in theory, we could also do sudo docker volume prune --all for removing unused volumes, but the disk usage by volumes was too low to justify finding out if it breaks anything.

Does anyone have comments on whether this is correct/doesn’t go far enough/is awful? Thanks!

NB: In case you’re reading this because you’re trying to reduce your disk usage, have a look at removing unused node versions and cleaning your logs.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.