Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does `docker-compose logs` pull from?

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?

like image 359
Ryan Avatar asked Sep 01 '18 15:09

Ryan


People also ask

Where are Docker compose logs stored?

You find these JSON log files in the /var/lib/docker/containers/ directory on a Linux Docker host.

Where do docker logs come from?

Docker container logs are generated by the Docker containers. They need to be collected directly from the containers. Any messages that a container sends to stdout or stderr is logged then passed on to a logging driver that forwards them to a remote destination of your choosing.

Does Docker compose pull?

That means docker-compose build will not build the buildchaintest docker image—it will just directly pull and run the docker image tag. Since docker-compose build doesn't attempt to build buildchaintest , there's no point to trying to tag or push that image after invoking it.


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"
like image 50
Rickkwa Avatar answered Nov 04 '22 14:11

Rickkwa


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.

like image 43
codemonkey Avatar answered Nov 04 '22 15:11

codemonkey