How to deal with too many Docker logs causing the disk to fill up

How to deal with too many Docker logs causing the disk to fill up

I have a server with multiple docker containers deployed on it, and each docker container continuously outputs logs to stderr, causing the disk to be full today. After searching, I found an article on the Docker official website that provides a solution.

The Docker container writes to /var/lib/docker when it is started/restarted. If you encounter the problem of No space left on device when starting the Docker container, you can follow the steps below to clean up the related log operations.

1. Sort the folders under /var/lib/docker/containers to see which container is taking up too much disk space

$ du -d1 -h /var/lib/docker/containers | sort -h

The above command will sort the container folders in ascending order and list the sizes of the container folders:

[root@dbl14195 testnet]# du -d1 -h /var/lib/docker/containers | sort -h
36K /var/lib/docker/containers/4d91f92dd7604216f2e9e123572e9a80d7bbee3d8c8ce7be2ed241c572816fb6
40K /var/lib/docker/containers/374aa0ba92b37d829012282ff15c1bb838d95dedb54589874c4285991be2d4aa
40K /var/lib/docker/containers/7cfdbc453b2f7109b52e974061754266e6cdc0ccaee62ab4a5887865113e1144
40K /var/lib/docker/containers/84ee24989ad52383c6e99eaa4d236e600095aa7f855e81fbafe10416b75ceefb
40K /var/lib/docker/containers/aeced3ef3e23df27e52f65743bb05448b46a2c660acc5b0aab12604e060779b4
40K /var/lib/docker/containers/c36722baf0d2e1c22b7dde9979665ab62cd8ab85c3f1d0f427bb7a34e0fd977a
44K /var/lib/docker/containers/62477b332d18e192d70c7420435d47a379e6bbd8de13da8a8762e0fd95b341ca
44K /var/lib/docker/containers/78da0cf9743b6940fabbbd8c574b99dc5deb642fa998a8f819a6c6978fc875d7
44K /var/lib/docker/containers/9f63daf7caa7c469385bed4b178fbfe662e15b8c569c6644081af090f8e40426
44K /var/lib/docker/containers/e2d1286119a45aac7e58d6dac6e4b44b1d1288799b735943be45abed50244e56
56K /var/lib/docker/containers/ebd1bd211a1b9d02bb39bfb80eec3d0960a5b25e18f54d7371781ec456e7a1e8
176K /var/lib/docker/containers/1fe0a241e5ce9726c547c68739793633f9dd906768a36fe80e8fb80373aa3bfb
17M /var/lib/docker/containers/ac30e68d454b37d22b3964053a2b52ba043baa1add13556a09c0e3e05589104f
25M /var/lib/docker/containers/872ca4e3d005594591ca2df0e832d36eef448981ab2820c69df4ff1399f8423e
25M /var/lib/docker/containers/bd49a0a0368b99a9f69981d8b921ea1830957451577b635a07d5425d48e1144b
30M /var/lib/docker/containers/8f732390a020a6ef647fabb04da32c87d6341b72ac2af6bb4a1cf5743fda54db
88M /var/lib/docker/containers/648e883aa0a93f696f64e4ab76434657f4845769fe1eaaad49c2dc1d7960f2b0
171M /var/lib/docker/containers/8de7ff9f0276586a6ab346c2be1c9dc879bbb0d795fa7776c1d8d1568ea2794a
354M /var/lib/docker/containers

2. Select the container you want to clean.

$ cat /dev/null > /var/lib/docker/containers/container_id/container_log_name

The above command will clear the corresponding log, such as:

cat /dev/null > /var/lib/docker/containers/374aa0ba92b37d829012282ff15c1bb838d95dedb54589874c4285991be2d4aa/374aa0ba92b37d829012282ff15c1bb838d95dedb54589874c4285991be2d4aa-json.log

Summarize

The above is the solution I introduced to you when the disk is full due to too many Docker logs. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Solution to the problem of Docker taking up all the disk space
  • Solve the problem of docker data files being too large and causing the root disk to be full
  • How to analyze and clean up Docker disk space usage
  • Summary of some situations when Docker container disk is full

<<:  Linux server quick uninstall and install node environment (easy to get started)

>>:  Detailed explanation of keywords and reserved words in MySQL 5.7

Recommend

Docker implements container port binding local port

Today, I encountered a small problem that after s...

17 JavaScript One-Liners

Table of contents 1. DOM & BOM related 1. Che...

How to completely uninstall node and npm on mac

npm uninstall sudo npm uninstall npm -g If you en...

Analysis of the advantages of path.join() in Node.js

You might be wondering why you should use the pat...

CentOS 7 method to modify the gateway and configure the IP example

When installing the centos7 version, choose to co...

Analysis of Sysbench's benchmarking process for MySQL

Preface 1. Benchmarking is a type of performance ...

Detailed explanation of the usage of DECIMAL in MySQL data type

Detailed explanation of the usage of DECIMAL in M...

Docker image management common operation code examples

Mirroring is also one of the core components of D...

MySQL installation tutorial under Centos7

MySQL installation tutorial, for your reference, ...

RGBA alpha transparency conversion calculation table

Conversion between rgba and filter values ​​under...

Discussion on default margin and padding values ​​of common elements

Today we discussed the issue of what the margin v...