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-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:

  • Codeception web driver (Selenium on Docker) tests not working as unable to see other containers (works on my dev machine though?!)
  • How to restrict Docker containers to run on specific CPU cores or group of CPU cores
  • How to install zless in alpine linux?
  • How to use docker to spin up postgres database
  • Kubernetes private registry doesn't work
  • Using docker image to store data files
  • $ 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?

  • CentOS 7.0 docker fail to start service
  • Adding standard CA roots to busybox docker image
  • Why set VISIBLE=NOW in /etc/profile?
  • DHCP interface on docker
  • Docker container reach outside network addresses
  • How to test docker image with external script
  • 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.

    --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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.