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:

  • Docker Port Forwarding
  • How can I access a docker container via ip address
  • Docker with a new nameserver
  • Docker web panel with permissions checking
  • Cron jobs using Whenever with VM, Docker & Dokku
  • Docker CMD to start Haproxy in Dockerfile
  • $ 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?

  • How to configue Pydev test runner to use Docker
  • Best practice for redirecting between docker containers
  • CircleCI: Best way to verify if docker containers are responding via HTTP
  • Run HBase inside docker container
  • How to get Shared file system for docker containers running on different hosts?
  • Using COPY on dockerfile for apache build
  • 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.