Solution to Docker disk space cleaning

Solution to Docker disk space cleaning

Some time ago, I encountered the problem that the docker disk space was too small and data could not be written. The reason was that I ran multiple MySQL containers locally (Mac Pro) and imported some online data. In the end, there was no free space before the import was completed.

I initially allocated 80GB of disk space to Docker, and when writing failed, only 0.6GB was left.

You can use the following command to view the disk usage of Docker containers and images:

docker system df

You can see output similar to the following, including images, containers, local volumes, and build cache:

TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 5 5 5.158GB 0B (0%)
Containers 6 6 7.601MB 0B (0%)
Local Volumes 4 3 46.64GB 207MB (0%)
Build Cache 34 0 1.609MB 1.609MB

It can be seen that among the above four types, Local Volumes occupies the largest disk space. If you want to view a more detailed report, use the following command.

docker system df -v

You can see a lot of output, including the following about Local Volumes:

VOLUME NAME LINKS SIZE
641d4976908910dca270a2bf5edf33408daf7474a0f27c850b6580b5936b6dd0 1 40.1GB
ovpn-data 1 33.51kB
267b52c5eab8c6b8e0f0d1b02f8c68bdaffba5ea80a334a6d20e67d22759ef48 1 6.325GB
f4a3866ef41e3972e087883f8fa460ad947b787f2eafb6545c759a822fb6e30d 0 207MB

In order to free up space, the first simple and crude method that comes to mind is to delete all stopped containers. The command is as follows.

docker system prune -a

However, you should be cautious when using this command. Remember to start all the Docker containers you need to use first, otherwise those containers that have not been started will be deleted by this command. For security reasons, this command will not delete data volumes that are not referenced by any container by default. If you need to delete these data volumes at the same time, you need to explicitly specify --volumns.

So if you want to forcibly delete containers, networks, images, and data volumes, you can use the following command.

docker system prune --all --force --volumes

The second method is to change the path where Docker stores data to another place with more disk space. If you are a Mac user, you can modify the Disk image location setting in the graphical Docker Desktop settings.

I tried the second method, changing the Disk image location to an external SSD, and tried to sync the previous data there first. Later, I found a big problem, which is that importing data into the mysql container is very slow. This is probably the writing bottleneck of the external SSD in the docker container.

If you just want to run a few containers and not store database data locally, then storing docker data to SSD is a good idea.

This is the end of this article about the solution to docker disk space cleaning. For more relevant docker disk space cleaning content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • About Docker's cleanup of Overlay2's occupied disk space (tested and effective)
  • Solve the problem of insufficient docker disk space
  • How to clean up the disk space occupied by Docker
  • How to analyze and clean up Docker disk space usage
  • Solution to the problem of Docker taking up all the disk space
  • Solution to the problem of insufficient disk space and inaccessibility caused by Docker container

<<:  In-depth understanding of the use of CSS clear:both

>>:  Personalized and creative website design examples (30)

Recommend

Util module in node.js tutorial example detailed explanation

Table of contents Starting from type judgment Str...

A brief introduction to bionic design in Internet web design

When it comes to bionic design, many people will t...

js implements custom drop-down box

This article example shares the specific code of ...

How to delete table data in MySQL

There are two ways to delete data in MySQL, one i...

Introduction to HTML Chinese Character Encoding Standard

In HTML, you need to specify the encoding used by...

Detailed tutorial on installing MySQL 8 in CentOS 7

Prepare Environmental information for this articl...

How to modify the group to which a user belongs in Linux

Modify the group to which a user belongs in Linux...

sql script function to write postgresql database to implement parsing

This article mainly introduces the sql script fun...

How to separate static and dynamic state by combining Apache with Tomcat

Experimental environment Apache and Tomcat are bo...

Detailed description of ffmpeg Chinese parameters

FFMPEG 3.4.1 version parameter details Usage: ffm...

MySQL 5.7.15 installation and configuration method graphic tutorial (windows)

Because I need to install MySQL, I record the ins...