简体   繁体   中英

How to cleanup docker?

We are using docker for continuous builds. I have removed the unwanted images and containers. Just have 4 images of 5GB max. But looks like something else is eating up all the disk space. Any tips how to cleanup and improve space?

    Filesystem      Size  Used Avail Use% Mounted on
udev             48G     0   48G   0% /dev
tmpfs           9.5G   26M  9.5G   1% /run
/dev/sda1       456G  428G  5.2G  99% /
tmpfs            48G  7.4M   48G   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            48G     0   48G   0% /sys/fs/cgroup
tmpfs           100K     0  100K   0% /run/lxcfs/controllers
tmpfs           9.5G     0  9.5G   0% /run/user/1000
none            456G  428G  5.2G  99% /var/lib/docker/aufs/mnt/4b96935f7fb6b517031df23849292a06eab92013d0610d922588688132013a5e
shm              64M     0   64M   0% /var/lib/docker/containers/c3b48e0215e05e13f79466de64cb0a2b4646cef30e020e651c59cb1950f0d70d/shm
none            456G  428G  5.2G  99% /var/lib/docker/aufs/mnt/4388442c65c13654a7d1cd51894aa5c06137166628a0a52d6854abc230417140
shm              64M     0   64M   0% /var/lib/docker/containers/027ce91cd66eca1ed134decdb8c13e6676fd34b1f6affe406513220037e63936/shm
none            456G  428G  5.2G  99% /var/lib/docker/aufs/mnt/13595cb64024d0d8f3cf7c09f90e37baccee08ea9b9b624c41d971a195d614e0
shm              64M     0   64M   0% /var/lib/docker/containers/3212761e701699313a127d50a423677c1d0ddaf9099ae37e23b25b8caaa72b37/shm
none            456G  428G  5.2G  99% /var/lib/docker/aufs/mnt/149839edbef826cdf289e66988c206dd6afebdb4257cc22e91551f65ea034f77
shm              64M     0   64M   0% /var/lib/docker/containers/9c084651b9ecf035257a34b9dd4415689e4c685e660e3013ad9673955834be

After Docker version 1.13, there are new prune commands to cleanup docker environment.

use docker system df to get statistics about containers, images and their disk usages with reclaimable space.

use docker system prune to get rid of stopped containers, dangling volumes and dangling images.

To remove only stopped containers you can use docker container prune and docker image prune to remove all dangling images.

The common mistake is to forget to delete the volumes.

For CI and CD it's a good practice to use docker rm -v when removing a container, with the -v you are sure that the auto-created volumes are deleted.

To be sure, type docker volume ls if you have some values here that means that some of your containers created some volumes.

You can get rid of them all at once with docker volume rm $(docker volume ls -q) (it will not remove any currently used volumes and will display an error message instead, but use with caution)

You can clean up docker artifacts by using the following command (depending on what you need to clean up):

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

These commands support '-a' option that will delete all of the artifacts if specified (for example docker container prune -a will remove all the containers)

In case you need to clean up everything you may want to use:

docker system prune -a

This is like all of the commands mentioned above combined.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM