Limiting docker logging
I have an application that runs user code. I’d like to make sure Docker is not collecting too many logs which I’ll anyway discard. For this, I’m trying to use
max-file logging options to get just the last few kilobytes of the user output and discard the rest, but that does not seem to work.
If I do:
$ docker run --log-opt max-size=2 --log-opt max-file=1 python:2 python -c "for i in range(10): print i" 0 1 2 3 4 5 6 7 8 9
Then it still prints the full output on the screen. If I examine the logs manually on the host, I can see the files with the full output are there.
Shouldn’t I be getting only
9\n in this case? What am I doing wrong here?
One Solution collect form web for “Limiting docker logging”
Dockers JSON file log options won’t impact the stdout and stderr streamed to your
docker client. You will see the complete output when running in the foreground.
When you run
docker logs, information will be pulled back from file.
The maximum size requires a unit. kilobytes, megabytes or gigabytes.
This sets the size of a JSON log file so there is extra metadata compared to just the line length that contributes to the size.
You should fit a maximum of 14 log entries into 1k of space. Whether dockers log rotation is that accurate or not is another matter.
You are probably wasting time dealing with file sizes less than 4k in any case.