Skip to content

Instantly share code, notes, and snippets.

@lyovkin
Last active June 24, 2022 08:32
Show Gist options
  • Save lyovkin/1fe650a827eb375594e5ab806a866c5e to your computer and use it in GitHub Desktop.
Save lyovkin/1fe650a827eb375594e5ab806a866c5e to your computer and use it in GitHub Desktop.
Creating space by removing container logs
Similarly, the docker needs sufficient space in /var/lib/docker to write into it. So users get an error when the space is insufficient. Hence to create more space in the container, we remove large log files.
Our Support Engineers first list the log files. For this, we use the command,
du -d1 -h /var/lib/docker/containers | sort -h
The output of this command lists the container directories and log size. Hence, to clear the container log we use the command,
cat /dev/null > /var/lib/docker/containers/container_id/container_log_name
But, if there is no root access then we use the below command to prevent permission errors.
sudo sh -c "cat /dev/null > /var/lib/docker/containers/container_id/container_log_name"
Hence this resolves the error.
# sudo sh -c "truncate -s 0 /var/lib/docker/containers/*/*-json.log"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment