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:

  • Start Docker Containers on logon under Windows
  • How can I configure Calico to use a custom subnet as the default?
  • Dockerfile build using complex powershell script on windows container
  • How add parameter in project -stage.yaml for Swarm on docker
  • Returning value outside of function
  • Command docker run create empty container
  • $ docker run --log-opt max-size=2 --log-opt max-file=1 python:2 python -c "for i in range(10): print i"

    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?

  • What is a docker-compose.yml file?
  • Apache Access/Error Logs Not Populated in Docker Container with Supervisor D
  • Does Docker contain the Heardbleed exploit?
  • Why does Docker run so many processes to map ports though to my application?
  • docker registry with --insecure-registry and docker 1.5
  • Which is the Dockerfile encoding?
  • 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.


    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.