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?
You find these JSON log files in the /var/lib/docker/containers/ directory on a Linux Docker host.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With