lucasmac's blog

hacking.science.coffee

How to Delete Docker Container Log Files

Get Docker File Location

Open a terminal and run the following:

:~$ docker inspect --format='{{.LogPath}}' $(docker ps -a -q)

A similar result will be displayed:

/var/lib/docker/containers/d7707cd1cf0e955f72958a60d7b17c79b3a812970bce3a625f6179312d09cd46/d7707cd1cf0e955f72958a60d7b17c79b3a812970bce3a625f6179312d09cd46-json.log
/var/lib/docker/containers/48bd6a8d1bb4354bffbc61ab2b2b0127778d1c84453f6e6cdcb63be2d9719709/48bd6a8d1bb4354bffbc61ab2b2b0127778d1c84453f6e6cdcb63be2d9719709-json.log
/var/lib/docker/containers/fb1f74d8a4ff74160876efc13601211805e692ebfb3e5e03f98a481206cfde30/fb1f74d8a4ff74160876efc13601211805e692ebfb3e5e03f98a481206cfde30-json.log
/var/lib/docker/containers/d644cd46300758316c6d23fc0e60e744e0b63a2545cdef166fc66236b770d14b/d644cd46300758316c6d23fc0e60e744e0b63a2545cdef166fc66236b770d14b-json.log
/var/lib/docker/containers/171ead11c41a4427b34c142808b06f4d055519025676a4154673613442cac638/171ead11c41a4427b34c142808b06f4d055519025676a4154673613442cac638-json.log

Find the file path, mine is /var/lib/docker/containers/.

Delete Log Files


WARNING:
our docker log file path should be /var/lib/docker/containers/, but if it isn’t, then change it in the command below.


Run:

:~$ find /var/lib/docker/containers/ -type f -name "*.log" -delete

Troubleshooting

  • Prefix the find and docker commands with sudo if you get a permission denied message.