Zapnuk
Zapnuk

Reputation: 645

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?

Upvotes: 19

Views: 8005

Answers (3)

gai-jin
gai-jin

Reputation: 853

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

Upvotes: 2

Tu Phung
Tu Phung

Reputation: 31

You can use another Docker Log Driver for streaming log to External Log Server (Setup in Another Host Machine with external drive). Docker is supporting many driver: Description here: https://docs.docker.com/config/containers/logging/configure/

Upvotes: 1

George Bekh-Ivanov
George Bekh-Ivanov

Reputation: 11

I'm not sure if there's an out-of-the-box solution for this.

One thing you can try though is to set lowest limits on your json-file logging driver, but save all the logs in the separate directory like so:

docker-compose logs -f 2>&1 | multilog t s1048576 n100 ./my_log_directory

You should run this in background to record all the logs

This bit is needed to treat all stderr as stdin so it will be saved by multilog:

2>&1

More info on multilog here: https://serverfault.com/questions/445118/rotating-logs-generated-by-a-process-that-logs-to-stdin#445461

Although it may work for your needs, you still will loose some information provided by json-file driver

Upvotes: 0

Related Questions