I would like to log all stdout messages of my containers to an external drive, as I only have limited space on the 'docker' drive.
With docker-compose v3 I save the logs in 10 MB chunks using the "json-file" driver
logging:
driver: "json-file"
options:
max-size: 10m
By default the resulting logs are saved at /var/lib/docker/containers/<container id>/<container id>-json.log
Is there any way to change this location?
By default, Docker stores log files in a dedicated directory on the host using the json-file log driver. The log file directory is /var/lib/docker/containers/<container_id> on the host where the container is running.
You can run the command kubectl exec -it <container_name> bash and use the command line inside the container to change the environment variable . You can do it by running the command export LOG_LEVEL=debug or export LOG_LEVEL=error inside the container.
Docker Command for Checking Container Logs Replace container_id with the ID number of the container you want to inspect. To find the container ID, use the docker ps command to list running containers. As in the image below, Docker responds by listing the event logs for that specific container in the output.
Straight- forward answer - NO, you can't
Why?
The file written by the
json-file
logging driver are not intended for consumption by external software, and should be regarded the "internal storage mechanism" for theJSON logging driver
. For that reason, the location is not configurable.If you want to have the logs written to a different location, consider using (e.g.) the
syslog
driver,journald
, or one of the drivers that allow sending the logs to a central log aggregator
Source: https://github.com/moby/moby/issues/29680
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