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

VMware Workstation 14 Pro installation Ubuntu 16.04 tutorial

This article records the specific method of insta...

How to use port 80 in Tomcat under Linux system

Application Scenario In many cases, we install so...

Detailed explanation of MySQL sql99 syntax inner join and non-equivalent join

#Case: Query employee salary levels SELECT salary...

How to enable JMX monitoring through Tomcat

Build a simulation environment: Operating system:...

Detailed explanation of keywords and reserved words in MySQL 5.7

Preface The keywords of MySQL and Oracle are not ...

Tips and precautions for using MySQL index

1. The role of index In general application syste...

How to let DOSBox automatically execute commands after startup

Using DOSBox, you can simulate DOS under Windows ...

How to upgrade MySQL 5.6 to 5.7 under Windows

Written in front There are two ways to upgrade My...

Complete steps to use element in vue3.0

Preface: Use the element framework in vue3.0, bec...

Vue axios interceptor commonly used repeated request cancellation

introduction The previous article introduced the ...