Skip to content

Instantly share code, notes, and snippets.

@innateessence
Last active September 1, 2024 23:41
Show Gist options
  • Save innateessence/ab022646a49286b2bfd80a7f8dd50585 to your computer and use it in GitHub Desktop.
Save innateessence/ab022646a49286b2bfd80a7f8dd50585 to your computer and use it in GitHub Desktop.
Wipe your Docker Logs
#!/usr/bin/env bash
# I am aware this can be handled via configuration instead.
# But sometimes, a script that solves the problem is better.
# This CAN cause issues if this runs while docker is appending logs to the file.
# It is possibly that if you use this, `docker logs` will throw an error due to a partial log entry being present and unparsable by docker.
# Don't use this if you don't understand what I just said in the line above.
LOG_PATH="$HOME/Library/Containers/com.docker.docker/Data/log/host"
function wipe_log(){
# $1: log file path
# example usage:
# wipe_log "$LOG_PATH/monitor.log.0"
local log_file="$1"
truncate -s 0 "$log_file"
}
function Main(){
for log_file in "$LOG_PATH"/* ; do
wipe_log "$log_file"
done
du -sh "$LOG_PATH"
}
Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment