docker clean up container overhead

347 Views Asked by At

I have two docker containers running, where the diskspace is as follows:

user$ sudo docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              2                   1                   448.3MB             1.84kB (0%)
Containers          2                   2                   284.4MB             0B (0%)
Local Volumes       7                   2                   418.8kB             176.4kB (42%)
Build Cache         0                   0                   0B                  0B

If I check diskusage I get:

root:/var/lib/docker# du -ah --max-depth=1
45G     ./containers

What can I do to keep the containers (since I made a lot of configuration) but remove the obvious overhead?

2

There are 2 best solutions below

2
On

Please run the below command the clean the system as

  1. This will remove:
    • all stopped containers
    • all networks not used by at least one container
    • all dangling images
    • all dangling build cache
docker system prune -f 

And yes, you can remove the son file as well.

0
On

You can use docker system prune -f, but, from my experience, it is not cleaning all that can be cleaned up.

For that, I've created a simple Docker image that does all the needed cleaning using only one command:

docker run -v /var/run/docker.sock:/var/run/docker.sock tikalci/tci-docker-cleanup:latest

For more details, see: https://github.com/TikalCI/tci-docker-cleanup