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.
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)
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).
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