How to clean Docker container logs?

后端 未结 7 1432
星月不相逢
星月不相逢 2020-12-23 10:47

I read my Docker container log output using

docker logs -f 

I log lots of data to the log in my node.js app via call

7条回答
  •  Happy的楠姐
    2020-12-23 11:32

    This is not the ideal solution, but until Docker builds in a command to do it, this is a good workaround.

    Create a script file docker-clean-logs.sh with this content:

    #!/bin/bash
    
    rm $(docker inspect $1 | grep -G '"LogPath": "*"' | sed -e 's/.*"LogPath": "//g' | sed -e 's/",//g');
    

    Grant the execute permission to it:

    chmod +x ./docker-clean-logs.sh
    

    Stop the Docker container that you want to clean:

    docker stop 
    

    Then run the above script:

    ./docker-clean-logs.sh 
    

    And finally run your container again:

    docker start ...
    

    Credit goes to the user sgarbesi on this page: https://github.com/docker/compose/issues/1083

提交回复
热议问题