Reputation: 5279
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-size
and 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?
Upvotes: 3
Views: 5169
Reputation: 74630
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.
--log-opt max-size=[0-9+][k|m|g]
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.
{"log":"1\n","stream":"stdout","time":"2016-05-30T07:39:31.265191929Z"}
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.
Upvotes: 6