How to clean Docker container logs?

后端 未结 7 1402
星月不相逢
星月不相逢 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条回答
  • 2020-12-23 11:45

    In order to do this on OSX, you need to get to the virtual machine the Docker containers are running in.

    You can use the walkerlee/nsenter image to run commands inside the VM like so:

    docker run --rm -it --privileged --pid=host walkerlee/nsenter -t 1 -m -u -i -n sh
    

    Combining that with a simplified version of the accepted answer you get:

    #!/bin/sh
    docker run --rm -it --privileged --pid=host walkerlee/nsenter -t 1 -m -u -i -n \
        cp /dev/null $(docker inspect -f '{{.LogPath}}' $1)
    

    Save it, chmod +x it, run it.

    As far as I can tell this doesn't require the container to be stopped. Also, it clears out the log file (instead of deleting it) avoiding errors when doing docker logs right after cleanup.

    0 讨论(0)
提交回复
热议问题