Where does `docker-compose logs` pull from?

Viewed 6187

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?

2 Answers

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"

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.

Related