Friday, December 23, 2022

Docker logs - how to write own logging driver

At a high level what is happening here is that docker consults a logging driver for the container which returns the “captured” STDOUT of your program. Each Docker daemon has a default logging driver, which each container uses, unless, you configure it to use a different logging driver

what Splunk driver does , sending program STDOUT to Splunk server


The Contract

A Log Driver plugin needs to handle following HTTP Requests —


Start Logging Request

Called when the container is started with the configured logging driver. There are couple of key things to understand about this request. As part of this HTTP request, Docker includes the ID of the container and also a handle to a named pipe for that container. STDOUT from the programs in the container is available on this FIFO and hence Driver should open this FIFO as a reader to continuously ingest the program output.


Stop Logging Request

Called when container is stopped. Gives Driver a chance to cleanup the resources allocated for reading the FIFO stream.


Get Supported Capabilities

Drivers can indicate whether they support ability to read logs (called when docker logs is invoked). For example, It may not make sense for a logging driver which ships log to remote location, to support this functionality


Read Logs

docker logs invokes this call on the driver, to retrieve logs.


Request body are in JSON format. I will not go into the detail of all the Request format. Please check out http.go here , for the request/response details


references:

https://github.com/monmohan/logdriver

https://software-factotum.medium.com/writing-a-docker-log-driver-plugin-7275d99d07be

No comments:

Post a Comment