Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the save location of docker containers logs?

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?

like image 848
Zapnuk Avatar asked Nov 20 '18 10:11

Zapnuk


People also ask

Where are docker logs saved?

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.

How do I change the log level in a docker container?

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.

What is the docker command for container logs?

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.


1 Answers

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 the JSON 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

like image 59
gai-jin Avatar answered Oct 19 '22 22:10

gai-jin