[LINUX] How to delete log with Docker, not to collect log

Overview

Hello, I have been placed in the teeth (@haniokasai). I ran out of space on my server and wanted to get rid of docker logs. I investigated how to erase / not collect logs.

environment

Delete existing log

Clear the log of a specific container

Enter the container name (ID) and get the log path. If you pour nothing into it, the log will disappear.

echo "" > $(docker inspect --format='{{.LogPath}}'Container name or container ID)

Clear all container logs

Turn the container name (ID) with for.

#Confirmation of deletion target
for CONTID in $(docker ps -qa); do echo $(docker inspect --format='{{.LogPath}}' $CONTID ); done
#Actual deletion
for CONTID in $(docker ps -qa); do echo "" > $(docker inspect --format='{{.LogPath}}' $CONTID ); done

Occasionally a blank container id gets in

bash: $(docker inspect --format='{{.LogPath}}' $CONTID ): ambiguous redirect

However, there is no problem ignoring it (there is no reason to divide the conditions).

How to not collect logs

Here's how to avoid logging in a ** new container **:

First, edit the service.

vi /lib/systemd/system/docker.service

You can edit ExecStart. --max-file is the number of generations to store --max-size is the maximum size

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --log-opt max-size=10m --log-opt max-file=1

like this

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --log-opt max-size=10m --log-opt max-file=1
ExecReload=/bin/kill -s HUP $MAINPID
((Omitted below)

Reload systemctl and docker.

systemctl daemon-reload
systemctl reload docker

Ref https://stackoverflow.com/questions/42510002/how-to-clear-the-logs-properly-for-a-docker-container https://www.unix.com/shell-programming-and-scripting/173276-how-loop-through-space-separated-values.html

Recommended Posts

How to delete log with Docker, not to collect log
How to Delete with SQLAlchemy?
How to delete a Docker container
How to log in to Docker + NGINX
How to install python3 with docker centos
How to selectively delete past tweets with Tweepy
How to delete the specified string with the sed command! !! !!
How to deal with Django's Template Does Not Exist
Output log to console with Flask + Nginx on Docker
How to share folders with Docker and Windows with tensorflow
How to update with SQLAlchemy?
How to cast with Theano
How to Alter with SQLAlchemy?
How to separate strings with','
How to RDP with Fedora31
How to not load images when using PhantomJS with Selenium
How to log in to AtCoder with Python and submit automatically
How to cancel RT with tweepy
Python: How to use async with
How to collect images in Python
How to use virtualenv with PowerShell
How to deal with imbalanced data
How to install python-pip with ubuntu20.04LTS
How to deal with imbalanced data
How to create / delete symbolic links
How to get started with Scrapy
How to get started with Python
How to deal with DistributionNotFound errors
How to get started with Django
How to Data Augmentation with PyTorch
How to use FTP with Python
How to write Docker base image
How to calculate date with python
How to install mysql-connector with pip3
How to INNER JOIN with SQLAlchemy
How to install Anaconda with pyenv
How to collect machine learning data
How to authenticate with Django Part 2
How to authenticate with Django Part 3
How to use jupyter notebook without polluting your environment with Docker
How to do arithmetic with Django template
[Blender] How to set shape_key with script
How to title multiple figures with matplotlib
How to collect Twitter data without programming
How to add a package with PyCharm
How to create an NVIDIA Docker environment
How to delete expired sessions in Django
How to install DLIB with 2020 / CUDA enabled
Check out how Docker works with bpftrace
How to use ManyToManyField with Django's Admin
How to use OpenVPN with Ubuntu 18.04.3 LTS
How to use Cmder with PyCharm (Windows)
Output Python log to console with GAE
How to prevent package updates with apt
Connect to MySQL with Python within Docker
How to work with BigQuery in Python
How to use Ass / Alembic with HtoA
How to deal with enum compatibility errors
How to use Japanese with NLTK plot
How to do portmanteau test with python
How to search Google Drive with Google Colaboratory