Where does `docker-compose logs` pull from?
Asked Answered
D

2

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?

Diphthong answered 1/9, 2018 at 15:13 Comment(0)
O
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"
Offing answered 1/9, 2018 at 16:28 Comment(2)
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.Diphthong
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).Offing
A
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.

Answer answered 1/9, 2018 at 16:32 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.