Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»General Articles»How to Clear Log Files of A Docker Container

    How to Clear Log Files of A Docker Container

    RahulBy RahulMarch 9, 20201 Min ReadUpdated:June 10, 2021

    This tutorial will help you clear the log file on a Docker container. If your system is getting out of disk space and you found that the docker container’s log files are consuming high disk space. you can find the log file location and clear them with the help of this tutorial. While clearing log files of a docker container, you don’t need to stop it.

    Clear Docker Container Log File

    First of all, find the log file location of a Docker container. Use inspect option to find the log file name and location.

    docker container inspect  --format='{{.LogPath}}' [CONTAINER ID/NAME] 
    

    Once you find the log file location, just truncate it with the following command.

    truncate -s 0 /path/to/logfile 

    Here -s is used to set the size of a file. You provided 0 as input, which means completely truncate the log file.

    How to find Docker Container ID/NAME

    Use the following command to view all containers including stopped containers. Remove -a command line parameter to list running containers only.

    docker container ps -a 

    You can also use sort command docker ps -a to view the same results.

    Docker log
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Install Redis on CentOS 8
    Next Article Magento 2 Codebase & Database Backup Script

    Related Posts

    How to Install Sublime Text 4 on Ubuntu 22.04

    2 Mins Read

    How to Find Django Install Location in Linux

    Updated:April 27, 20221 Min Read

    (Resolved) – ReactJS 404 Error on Page Reload

    2 Mins Read

    Adding a New SSH Key in GitHub

    Updated:April 1, 20223 Mins Read

    13 Best Linux Terminal Emulators and Bash Editors

    8 Mins Read

    How To Install Oracle VirtualBox on Debian 11

    2 Mins Read

    1 Comment

    1. Juraj on June 10, 2021 11:43 am

      oneline:
      docker inspect –format='{{.LogPath}}’ | xargs truncate -s 0

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install Sublime Text 4 on Ubuntu 22.04
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.