Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 426
Jeel Avatar asked Oct 13 '16 13:10

Jeel


People also ask

How do I delete old docker files?

To remove one or more Docker containers, use the docker container rm command, followed by the IDs of the containers you want to remove. If you get an error message similar to the one shown below, it means that the container is running. You'll need to stop the container before removing it.

How do I clean up unused Docker images?

The docker image prune command allows you to clean up unused images. By default, docker image prune only cleans up dangling images. A dangling image is one that is not tagged and is not referenced by any container. To remove dangling images: $ docker image prune WARNING! This will remove all dangling images.

How to clean up Docker networks that are not in use?

Once you hit enter you’ll be presented with all of the networks created on your docker host. In order to clean up docker networks that are not in use by a container then type the following command: WARNING! This will remove all networks not used by at least one container. Type y and docker will remove all of the networks that you are not using.

Is it time to clean up your Docker registry?

If you’re using your docker registry to push continuous updates you’ve probably noticed that the disk mount space for the registry is gradually growing. It looks like it’s time to have a registry clean up. Here’s how to do it. One docker image can have multiple tags. Each image has a digest, which is a unique value.

What happens when I delete a docker container?

Although some volumes are created manually, some containers automatically create volumes when they initially startup. If you delete those containers, the volumes will remain on the system. You can clean up docker volumes by running the following command in your terminal:


3 Answers

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)

like image 87
michael_bitard Avatar answered Oct 22 '22 22:10

michael_bitard


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.

like image 35
Ruwanka Madhushan Avatar answered Oct 22 '22 21:10

Ruwanka Madhushan


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.

like image 4
Danylo Zatorsky Avatar answered Oct 22 '22 21:10

Danylo Zatorsky