7

Like most people who downvoted the sparse Docker docs page here and here, I'm confused by what docker-compose logs does.

When I run cd /apps/laradock/ && docker-compose logs -f nginx, I see a very long output from many days ago til now.

What file or files is that pulling from?

The only nginx log file I could find was /apps/laradock/logs/nginx/error.log, and it doesn't have much in it (so isn't the same).

And is there a way to "log rotate" or otherwise ensure that I don't spend more than a certain amount of disk on logging?

codemonkey
  • 3,510
  • 3
  • 23
  • 35
Ryan
  • 22,332
  • 31
  • 176
  • 357

2 Answers2

14

With the default logging driver, json-file, your logs are stored in /var/lib/docker/containers/<container-id>/. Do note that what gets logged here is the output of stdout and stderr from PID 1 of your container.

As for "log rotate", the json-file driver has some options you can pass to it to limit the size per log file, and the maximum number of log files. See max-size, and max-file of the documentation.

With docker-compose, you can set the options like:

version: '3'

services:
  myservice:
    image: ...
    logging:
      options:
        max-file: "3"
        max-size: "50m"
Rickkwa
  • 2,197
  • 4
  • 23
  • 34
  • This answer seems like it would be in the right direction, but I just looked at my `docker-compose.yml`, and it says `version: '2.1'` and doesn't have the word "logging" anywhere in the file. And I don't *think* the what I see when I run `docker-compose logs -f nginx` is JSON format. Any idea where I should look to see how my current logging is configured? Thanks. – Ryan Sep 01 '18 at 16:31
  • 2
    The logs are stored as json on disk. But when you run `docker-compose logs`, it knows to parse the json and just output the raw text. And the compose version is just an example. Version 2.1 supports `logging` field. Your compose file doesn't have "logging" because it is leaving everything at the default (ie. no log rotation). – Rickkwa Sep 01 '18 at 16:33
5

It depends which logging driver is used.

You can check which one is configured for the Docker daemon with:

docker info -f '{{.LoggingDriver}}'

The default driver json-file logs to:

/var/lib/docker/containers/<container-id>/<container-id>-json.log

Docker compose then aggregates the logs for each container in the docker-compose.yml.

codemonkey
  • 3,510
  • 3
  • 23
  • 35